####Personalities of the Discontent - R Analysis File####
###Rory Truex, Assistant Professor, Princeton University Department of Politics and Woodrow Wilson School of Public and International Affairs, rtruex@princeton.edu###

###LOAD PACKAGES AND FUNCTIONS###
setwd('/Users/rtruex/Google Drive/The Personality of the Party/')
rm(list=ls(all=TRUE))

###INSTALL/LOAD PACKAGES###

library("foreign")
library("plyr")
library("qdap")
library("gridExtra")
library("rvest")
library("Amelia")
library("reshape2")
library("scales")
require("broom")
library("ggradar") 
suppressPackageStartupMessages(library(dplyr))
library("scales")
library("tibble")
require("ggplot2")
library("tidyverse")
library("mice")
library("miceadds")
library("ggstance")
library("readstata13")
library("texreg")
library("psych")
library(ggiraph)
library(ggiraphExtra)


###HELPER FUNCTIONS###

summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
                      conf.interval=.95, .drop=TRUE) {
  library(plyr)
  
  # New version of length which can handle NA's: if na.rm==T, don't count them
  length2 <- function (x, na.rm=FALSE) {
    if (na.rm) sum(!is.na(x))
    else       length(x)
  }
  
  # This does the summary. For each group's data frame, return a vector with
  # N, mean, and sd
  datac <- ddply(data, groupvars, .drop=.drop,
                 .fun = function(xx, col) {
                   c(N    = length2(xx[[col]], na.rm=na.rm),
                     mean = mean   (xx[[col]], na.rm=na.rm),
                     sd   = sd     (xx[[col]], na.rm=na.rm)
                   )
                 },
                 measurevar
  )
  
  # Rename the "mean" column    
  datac <- rename(datac, c("mean" = measurevar))
  
  datac$se <- datac$sd / sqrt(datac$N)  # Calculate standard error of the mean
  
  # Confidence interval multiplier for standard error
  # Calculate t-statistic for confidence interval: 
  # e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
  ciMult <- qt(conf.interval/2 + .5, datac$N-1)
  datac$ci <- datac$se * ciMult
  
  return(datac)
}

require(grid)
vp.layout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y)
arrange_ggplot2 <- function(..., nrow=NULL, ncol=NULL, as.table=FALSE) {
  dots <- list(...)
  n <- length(dots)
  if(is.null(nrow) & is.null(ncol)) { nrow = floor(n/2) ; ncol = ceiling(n/nrow)}
  if(is.null(nrow)) { nrow = ceiling(n/ncol)}
  if(is.null(ncol)) { ncol = ceiling(n/nrow)}
  
  grid.newpage()
  pushViewport(viewport(layout=grid.layout(nrow,ncol) ) )
  ii.p <- 1
  for(ii.row in seq(1, nrow)){
    ii.table.row <- ii.row  
    if(as.table) {ii.table.row <- nrow - ii.table.row + 1}
    for(ii.col in seq(1, ncol)){
      ii.table <- ii.p
      if(ii.p > n) break
      print(dots[[ii.table]], vp=vp.layout(ii.table.row, ii.col))
      ii.p <- ii.p + 1
    }
  }
}


#'The radar coordinate system is a modification of polar coordinate system, commonly used for radar chart
#'
#'@param theta variable to map angle to (x or y)
#'@param start offset of starting point from 12 o'clock in radians
#'@importFrom ggplot2 ggproto
#'
#'@export
#'@param direction 1, clockwise; -1, counterclockwise
coord_radar <- function (theta = "x", start = 0, direction = 1)
{
  theta <- match.arg(theta, c("x", "y"))
  r <- if (theta == "x")
    "y"
  else "x"
  ggproto("CoordRadar", ggplot2::CoordPolar, theta = theta, r = r, start = start,
          direction = sign(direction),
          is_linear = function(coord) TRUE)
}

#'Rescale all numeric variables of a data.frame except grouping variable
#'
#'@param data A data.frame
#'@param groupvar A column name used as a grouping variable
#'@importFrom scales rescale
#'
#'@export
#'@return A rescaled data.frame
rescale_df=function(data,groupvar=NULL){
  if(is.null(groupvar)) df=data
  else df=data[,-which(names(data) %in% groupvar)]
  
  select=sapply(df,is.numeric)
  df[select]=lapply(df[select], scales::rescale)
  if(!is.null(groupvar)) {
    df=cbind(df,data[groupvar])
    #colnames(df)[length(df)]=groupvar
  }
  df
}


#' extract variable name from mapping, aes
#' @param mapping aesthetic mapping
#' @param varname variable name to extract
#' @return variable name in character
#' @importFrom stringr str_replace_all str_detect str_split fixed
#' @importFrom utils packageVersion
#' @export
#' @examples
#' require(ggplot2)
#' mapping=aes(colour=sex)
#' mapping=aes(x=c(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width))
#' getMapping(mapping,"colour")
#' getMapping(mapping,"x")
getMapping=function(mapping,varname) {
  
  # mapping=aes(colour=sex)
  # varname="x"
  # mapping=aes(colour=am,facet=cyl);varname=c("colour","facet")
  
  if(is.null(mapping)) return(NULL)
  result=paste(mapping[varname])
  result
  if(length(result)==1){
    if(result=="NULL") result<-NULL
  } else{
    for(i in 1:length(result)){
      if(result[i]=="NULL") result[i]<-NULL
    }
  }
  if(!is.null(result)){
    if(packageVersion("ggplot2") > "2.2.1") {
      result=stringr::str_replace_all(result,"~","")
    }
    result=stringr::str_replace_all(result,stringr::fixed("c("),"")
    result=stringr::str_replace_all(result,stringr::fixed(")"),"")
    result=stringr::str_replace_all(result," ","")
    # res=c()
    # if(stringr::str_detect(result,",")) {
    result=unlist(stringr::str_split(result,","))
    # }
    
  }
  result
}


#'Draw a radar chart
#'
#'@param data A data.frame
#'@param mapping Set of aesthetic mappings created by aes or aes_.
#'@param rescale A logical value. If TRUE, all continuous variables in the data.frame are rescaled.
#'@param legend.position Legend position. One of c("top","bottom","left","right","none")
#'@param colour A name of color to be assigned as a color variable
#'@param alpha  Any numbers from 0 (transparent) to 1 (opaque)
#'@param size  Point size
#'@param ylim A numeric vector of length 2, giving the y coordinates ranges.
#'@param interactive A logical value. If TRUE, an interactive plot will be returned
#'@param scales should Scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")
#'@param use.label Logical. Whether or not use column label
#'@param ... other arguments passed on to geom_point
#'@importFrom reshape2 melt
#'@importFrom plyr ddply summarize
#'@importFrom ggiraph geom_polygon_interactive geom_point_interactive
#'@importFrom ggplot2 expand_limits theme xlab ylab
#'@importFrom stringr str_replace
#'@importFrom sjlabelled get_label
#'@return An interactive radar plot
#'@export
#'@examples
#'require(ggplot2)
#'require(ggiraph)
#'require(plyr)
#'require(reshape2)
#'require(moonBook)
#'require(sjmisc)
#'ggRadar(data=iris,aes(group=Species))
#'ggRadar(data=mtcars,interactive=TRUE)
#'ggRadar(data=mtcars,aes(colour=am,facet=cyl),interactive=TRUE)
#'ggRadar(data=acs,aes(colour=Dx,facet=Dx))
#'ggRadar(iris,aes(x=c(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width)))
ggRadar=function(data,mapping=NULL,
                 rescale=TRUE,
                 legend.position="top",
                 colour="red",
                 alpha=0.3,
                 size=3,
                 ylim=NULL,
                 scales="fixed",
                 use.label=FALSE,
                 interactive=FALSE,...){
  
  # data=iris;mapping=aes(group=Species);interactive=TRUE
  # rescale=TRUE;
  # legend.position="top";
  # colour="red";
  # alpha=0.3;
  # size=3;
  # ylim=NULL;
  # scales="fixed";
  # use.label=FALSE;
  
  
  data=as.data.frame(data)
  (groupname=setdiff(names(mapping),c("x","y")))
  # length(groupname)
  groupname
  mapping
  length(groupname)
  if(length(groupname)==0) {
    groupvar<-NULL
  } else {
    groupvar=getMapping(mapping,groupname)
  }
  groupvar
  facetname<-colorname<-NULL
  if ("facet" %in% names(mapping)){
    facetname <- getMapping(mapping,"facet")
  }
  (colorname=setdiff(groupvar,facetname))
  
  if((length(colorname)==0) &!is.null(facetname)) colorname<-facetname
  #if(length(groupvar)>1) warning("Only one grouping variable is allowed")
  data=num2factorDf(data,groupvar)
  
  (select=sapply(data,is.numeric))
  
  if("x" %in% names(mapping)) {
    xvars=getMapping(mapping,"x")
    xvars
    #if(length(xvars)>1) xvars<-xvars[-1]
    if(length(xvars)<3) warning("At least three variables are required")
    
  } else {
    xvars=colnames(data)[select]
  }
  
  (xvars=setdiff(xvars,groupvar))
  
  if(rescale) data=rescale_df(data,groupvar)
  
  temp=sjlabelled::get_label(data)
  cols=ifelse(temp=="",colnames(data),temp)
  
  if(is.null(groupvar)) {
    id=newColName(data)
    data[[id]]=1
    
    longdf=reshape2::melt(data,id.vars=id,measure.vars=xvars)
  } else{
    cols=setdiff(cols,groupvar)
    longdf=reshape2::melt(data,id.vars=groupvar,measure.vars=xvars)
  }
  #summary(longdf)
  
  temp=paste0("ddply(longdf,c(groupvar,'variable'),summarize,mean=mean(value,na.rm=TRUE))")
  df=eval(parse(text=temp))
  
  colnames(df)[length(df)]="value"
  df
  groupvar
  if(is.null(groupvar)){
    id2=newColName(df)
    df[[id2]]="all"
    id3=newColName(df)
    df[[id3]]=1:nrow(df)
    df$tooltip=paste0(df$variable,"=",round(df$value,1))
    df$tooltip2=paste0("all")
    #str(df)
    p<-ggplot(data=df,aes_string(x="variable",y="value",group=1))+
      geom_polygon_interactive(aes_string(tooltip="tooltip2"),colour=colour,fill=colour,alpha=alpha)+
      geom_point_interactive(aes_string(data_id=id3,tooltip="tooltip"),colour=colour,size=size)
    # geom_point_interactive(aes_string(data_id=id3,tooltip="tooltip"),colour=colour,size=size,...)
  } else{
    
    if(!is.null(colorname)){
      id2=newColName(df)
      df[[id2]]=df[[colorname]]
    }
    id3=newColName(df)
    df[[id3]]=1:nrow(df)
    df$tooltip=paste0(groupvar,"=",df[[colorname]],"<br>",df$variable,"=",round(df$value,1))
    df$tooltip2=paste0(groupvar,"=",df[[colorname]])
    #str(df)
    p<-ggplot(data=df,aes_string(x="variable",y="value",colour=colorname,fill=colorname,group=colorname))+
      geom_polygon_interactive(aes_string(tooltip="tooltip2"),alpha=alpha)+
      geom_point_interactive(aes_string(data_id=id3,tooltip="tooltip"),size=size)
    # geom_point_interactive(aes_string(data_id=id3,tooltip="tooltip"),size=size,...)
    # p<-ggplot(data=df,aes_string(x="variable",y="value",colour=colorname,fill=colorname,group=colorname))+
    #         geom_polygon_interactive(aes_string(tooltip="tooltip2"),alpha=alpha)+
    #         geom_point_interactive(aes_string(data_id=id3,tooltip="tooltip"),size=size)
    
  }
  p
  if(!is.null(facetname)) {
    formula1=as.formula(paste0("~",facetname))
    p<-p+facet_wrap(formula1,scales=scales)
  }
  
  p<- p+ xlab("")+ylab("")+theme(legend.position=legend.position)
  if(use.label) p<-p+scale_x_discrete(labels=cols)
  p<-p+coord_radar()
  
  if(!is.null(ylim)) p<-p+expand_limits(y=ylim)
  
  p
  if(interactive){
    tooltip_css <- "background-color:white;font-style:italic;padding:10px;border-radius:10px 20px 10px 20px;"
    #hover_css="fill-opacity=.3;cursor:pointer;stroke:gold;"
    hover_css="r:4px;cursor:pointer;stroke-width:6px;"
    selected_css = "fill:#FF3333;stroke:black;"
    p<-girafe(ggobj=p)
    p<-girafe_options(p,
                      opts_hover(css=hover_css),
                      opts_tooltip(css=tooltip_css,opacity=.75),
                      opts_selection(css=selected_css),
                      opts_zoom(min=1,max=10))
    
  }
  p
}

#' find new column name
#' @param df a data.frame
#' @export
newColName=function(df){
  temp="id"
  no=0
  while(1){
    id=paste0(temp,no)
    if(!(id %in% colnames(df))) return(id)
    no=no+1
  }
}



######CHINA PERSONALITY TEST######

###LOAD DATA###
data <- read.csv("HEXACO Qualtrics Final Data.csv",stringsAsFactors=FALSE)
data = data[-c(1:100),]
data = subset(data, data$gc==1) 

###GENERATE BASIC VARIABLES###

##Demographics##

colnames(data)[1] <- "id"
colnames(data)[2] <- "response.set"
colnames(data)[3] <- "start.time"
colnames(data)[4] <- "end.time"

data$total.minutes<- as.numeric(data$Q_TotalDuration)/60
hist(data$total.minutes)
summary(data$total.minutes)

#female
data$female<-NA
data$female[data$D1=="4"]<-0
data$female[data$D1=="5"]<-1
summary(data$female)

#age
data$age<-NA

data$age[data$D2=="1"]<-87
data$age[data$D2=="2"]<-86
data$age[data$D2=="3"]<-85
data$age[data$D2=="4"]<-84
data$age[data$D2=="5"]<-83
data$age[data$D2=="6"]<-82
data$age[data$D2=="7"]<-81
data$age[data$D2=="8"]<-80
data$age[data$D2=="9"]<-79
data$age[data$D2=="10"]<-78
data$age[data$D2=="11"]<-77
data$age[data$D2=="12"]<-76
data$age[data$D2=="13"]<-75
data$age[data$D2=="14"]<-74
data$age[data$D2=="15"]<-73
data$age[data$D2=="16"]<-72
data$age[data$D2=="17"]<-71
data$age[data$D2=="18"]<-70
data$age[data$D2=="19"]<-69
data$age[data$D2=="20"]<-68
data$age[data$D2=="21"]<-67
data$age[data$D2=="22"]<-66
data$age[data$D2=="23"]<-65
data$age[data$D2=="24"]<-64
data$age[data$D2=="25"]<-63
data$age[data$D2=="26"]<-62
data$age[data$D2=="27"]<-61
data$age[data$D2=="28"]<-60
data$age[data$D2=="29"]<-59
data$age[data$D2=="30"]<-58
data$age[data$D2=="31"]<-57
data$age[data$D2=="32"]<-56
data$age[data$D2=="33"]<-55
data$age[data$D2=="34"]<-54
data$age[data$D2=="35"]<-53
data$age[data$D2=="36"]<-52
data$age[data$D2=="37"]<-51
data$age[data$D2=="38"]<-50
data$age[data$D2=="39"]<-49
data$age[data$D2=="40"]<-48
data$age[data$D2=="41"]<-47
data$age[data$D2=="42"]<-46
data$age[data$D2=="43"]<-45
data$age[data$D2=="44"]<-44
data$age[data$D2=="45"]<-43
data$age[data$D2=="46"]<-42
data$age[data$D2=="47"]<-41
data$age[data$D2=="48"]<-40
data$age[data$D2=="49"]<-39
data$age[data$D2=="50"]<-38
data$age[data$D2=="51"]<-37
data$age[data$D2=="52"]<-36
data$age[data$D2=="53"]<-35
data$age[data$D2=="54"]<-34
data$age[data$D2=="55"]<-33
data$age[data$D2=="56"]<-32
data$age[data$D2=="57"]<-31
data$age[data$D2=="58"]<-30
data$age[data$D2=="59"]<-29
data$age[data$D2=="60"]<-28
data$age[data$D2=="61"]<-27
data$age[data$D2=="62"]<-26
data$age[data$D2=="63"]<-25
data$age[data$D2=="64"]<-24
data$age[data$D2=="65"]<-23
data$age[data$D2=="66"]<-22
data$age[data$D2=="67"]<-21
data$age[data$D2=="68"]<-20
data$age[data$D2=="69"]<-19
data$age[data$D2=="70"]<-18
data$age[data$D2=="71"]<-17
data$age[data$D2=="72"]<-16
data$age[data$D2=="73"]<-15
data$age[data$D2=="74"]<-14
data$age[data$D2=="75"]<-13
data$age[data$D2=="76"]<-12
summary(data$age)

#residence
data$res.urban<-NA
data$res.urban[data$D4=="4"]<-0
data$res.urban[data$D4=="5"]<-0
data$res.urban[data$D4=="6"]<-1
summary(data$res.urban)

#minority
data$minority<-NA
data$minority[data$D6=="1"]<-0
data$minority[data$D6=="2"]<-1
summary(data$minority)

#lowed
data$lowed<-NA
data$lowed[data$D7a=="1"]<-1
data$lowed[data$D7a=="2"]<-1
data$lowed[data$D7a=="3"]<-1
data$lowed[data$D7a=="4"]<-1
data$lowed[data$D7a=="5"]<-1
data$lowed[data$D7a=="6"]<-1
data$lowed[data$D7a=="7"]<-0
data$lowed[data$D7a=="8"]<-0
data$lowed[data$D7a=="9"]<-0
data$lowed[data$D7a=="10"]<-NA
summary(data$lowed)

#edulevels
data$edu.univ<-NA
data$edu.univ[data$D7a=="1"]<-0
data$edu.univ[data$D7a=="2"]<-0
data$edu.univ[data$D7a=="3"]<-0
data$edu.univ[data$D7a=="4"]<-0
data$edu.univ[data$D7a=="5"]<-0
data$edu.univ[data$D7a=="6"]<-0
data$edu.univ[data$D7a=="7"]<-1
data$edu.univ[data$D7a=="8"]<-0
data$edu.univ[data$D7a=="9"]<-0
data$edu.univ[data$D7a=="10"]<-NA

data$edu.maphd<-NA
data$edu.maphd[data$D7a=="1"]<-0
data$edu.maphd[data$D7a=="2"]<-0
data$edu.maphd[data$D7a=="3"]<-0
data$edu.maphd[data$D7a=="4"]<-0
data$edu.maphd[data$D7a=="5"]<-0
data$edu.maphd[data$D7a=="6"]<-0
data$edu.maphd[data$D7a=="7"]<-0
data$edu.maphd[data$D7a=="8"]<-1
data$edu.maphd[data$D7a=="9"]<-1
data$edu.maphd[data$D7a=="10"]<-NA

#ccp 
data$ccp<-NA
data$ccp[data$D9a=="1"]<-1
data$ccp[data$D9a=="2"]<-0
summary(data$ccp) 
ftable(data$ccp)

#ccp.year
data$ccp.year<-NA
data$ccp.year<-98-as.numeric(data$D9b) 
summary(data$ccp.year) 

#ccp.applied
data$ccp.applied<-NA
data$ccp.applied[data$D9c=="4"]<-1
data$ccp.applied[data$D9c=="5"]<-0
summary(data$ccp.applied)
ftable(data$ccp.applied)
ftable(data$ccp.applied, data$ccp)

#ccp.target
data$ccp.target<-NA
data$ccp.target[data$D9d=="4"]<-1
data$ccp.target[data$D9d=="5"]<-0
summary(data$ccp.target)

#party.mem
data$party.mem<-NA
data$party.mem<-"non member"
data$party.mem[data$ccp=="1"]<-"member"
data$party.mem[data$ccp.applied=="1"]<-"rejected applicant"
ftable(data$party.mem)

#discontent
data$discontent<-NA
data$discontent[data$C1_1=="11"]<-0
data$discontent[data$C1_1=="10"]<-0
data$discontent[data$C1_1=="9"]<-0
data$discontent[data$C1_1=="8"]<-0
data$discontent[data$C1_1=="7"]<-0
data$discontent[data$C1_1=="6"]<-0
data$discontent[data$C1_1=="5"]<-1 
data$discontent[data$C1_1=="4"]<-1
data$discontent[data$C1_1=="3"]<-1
data$discontent[data$C1_1=="2"]<-1
data$discontent[data$C1_1=="1"]<-1

#discontent.alt
data$discontent.alt<-NA
data$discontent.alt[data$C1_1=="11"]<-0
data$discontent.alt[data$C1_1=="10"]<-0
data$discontent.alt[data$C1_1=="9"]<-0
data$discontent.alt[data$C1_1=="8"]<-0
data$discontent.alt[data$C1_1=="7"]<-1
data$discontent.alt[data$C1_1=="6"]<-1
data$discontent.alt[data$C1_1=="5"]<-1 
data$discontent.alt[data$C1_1=="4"]<-1
data$discontent.alt[data$C1_1=="3"]<-1
data$discontent.alt[data$C1_1=="2"]<-1
data$discontent.alt[data$C1_1=="1"]<-1

#selfcens
data$selfcens<-0
data$selfcens[is.na(data$discontent)==TRUE]<-1
ftable(data$selfcens)

#sat.central
data$sat.central<-NA
data$sat.central[data$C1_1=="11"]<-10
data$sat.central[data$C1_1=="10"]<-9
data$sat.central[data$C1_1=="9"]<-8
data$sat.central[data$C1_1=="8"]<-7
data$sat.central[data$C1_1=="7"]<-6
data$sat.central[data$C1_1=="6"]<-5
data$sat.central[data$C1_1=="5"]<-4
data$sat.central[data$C1_1=="4"]<-3
data$sat.central[data$C1_1=="3"]<-2
data$sat.central[data$C1_1=="2"]<-1
data$sat.central[data$C1_1=="1"]<-0
ftable(data$sat.central)
hist(data$sat.central)
summary(data$sat.central)

#sat.local
data$sat.local<-NA
data$sat.local[data$C1_2=="11"]<-10
data$sat.local[data$C1_2=="10"]<-9
data$sat.local[data$C1_2=="9"]<-8
data$sat.local[data$C1_2=="8"]<-7
data$sat.local[data$C1_2=="7"]<-6
data$sat.local[data$C1_2=="6"]<-5
data$sat.local[data$C1_2=="5"]<-4
data$sat.local[data$C1_2=="4"]<-3
data$sat.local[data$C1_2=="3"]<-2
data$sat.local[data$C1_2=="2"]<-1
data$sat.local[data$C1_2=="1"]<-0
ftable(data$sat.local)
hist(data$sat.local)
summary(data$sat.local)

##Participation##

data$part.meeting<-NA
data$part.meeting[data$D10a_4=="1"]<-1
data$part.meeting[data$D10a_4=="2"]<-0
data$part.meeting[data$D10a_4=="3"]<-NA
summary(data$part.meeting)

data$part.opinleaders<-NA
data$part.opinleaders[data$D10a_5=="1"]<-1
data$part.opinleaders[data$D10a_5=="2"]<-0
data$part.opinleaders[data$D10a_5=="3"]<-NA
summary(data$part.opinleaders)

data$part.opinmedia<-NA
data$part.opinmedia[data$D10a_6=="1"]<-1
data$part.opinmedia[data$D10a_6=="2"]<-0
data$part.opinmedia[data$D10a_6=="3"]<-NA
summary(data$part.opinmedia)

data$part.voted<-NA
data$part.voted[data$D10a_7=="1"]<-1
data$part.voted[data$D10a_7=="2"]<-0
data$part.voted[data$D10a_7=="3"]<-NA
summary(data$part.voted)

data$part.protest<-NA
data$part.protest[data$D10a_8=="1"]<-1
data$part.protest[data$D10a_8=="2"]<-0
data$part.protest[data$D10a_8=="3"]<-NA
summary(data$part.protest)

data$part.onlinecrit<-NA
data$part.onlinecrit[data$D10a_9=="1"]<-1
data$part.onlinecrit[data$D10a_9=="2"]<-0
data$part.onlinecrit[data$D10a_9=="3"]<-NA
summary(data$part.onlinecrit)

data$part.onlinediscprotest<-NA
data$part.onlinediscprotest[data$D10a_10=="1"]<-1
data$part.onlinediscprotest[data$D10a_10=="2"]<-0
data$part.onlinediscprotest[data$D10a_10=="3"]<-NA
summary(data$part.onlinediscprotest)

data$part.petition<-NA
data$part.petition[data$D10a_11=="1"]<-1
data$part.petition[data$D10a_11=="2"]<-0
data$part.petition[data$D10a_11=="3"]<-NA
summary(data$part.petition)

data$altruism.blood<-NA
data$altruism.blood[data$D10a_15=="1"]<-1
data$altruism.blood[data$D10a_15=="2"]<-0
data$altruism.blood[data$D10a_15=="3"]<-NA
summary(data$altruism.blood)

data$altruism.money<-NA
data$altruism.money[data$D10a_16=="1"]<-1
data$altruism.money[data$D10a_16=="2"]<-0
data$altruism.money[data$D10a_16=="3"]<-NA
summary(data$altruism.money)

data$altruism.volunteer<-NA
data$altruism.volunteer[data$D10a_17=="1"]<-1
data$altruism.volunteer[data$D10a_17=="2"]<-0
data$altruism.volunteer[data$D10a_17=="3"]<-NA
summary(data$altruism.volunteer)

##Personality##
data$H1nF<-6-as.numeric(as.character(data$H1)) 
data$H2nF<-as.numeric(as.character(data$H2))
data$H3nF<-as.numeric(as.character(data$H3))
data$H4nF<-as.numeric(as.character(data$H4))
data$H5nF<-as.numeric(as.character(data$H5))
data$H6nF<-as.numeric(as.character(data$H6))
data$H7nF<-as.numeric(as.character(data$H7))
data$H8nF<-as.numeric(as.character(data$H8))
data$H9nF<-6-as.numeric(as.character(data$H9))
data$H10nF<-6-as.numeric(as.character(data$H10))
data$H11nF<-as.numeric(as.character(data$H11))
data$H12nF<-6-as.numeric(as.character(data$H12))
data$H13nF<-as.numeric(as.character(data$H13))
data$H14nF<-6-as.numeric(as.character(data$H14))
data$H15nF<-6-as.numeric(as.character(data$H15))
data$H16nF<-as.numeric(as.character(data$H16))
data$H17nF<-as.numeric(as.character(data$H17))
data$H18nF<-as.numeric(as.character(data$H18))
data$H19nF<-6-as.numeric(as.character(data$H19))
data$H20nF<-6-as.numeric(as.character(data$H20))
data$H21nF<-6-as.numeric(as.character(data$H21))
data$H22nF<-as.numeric(as.character(data$H22))
data$H23nF<-as.numeric(as.character(data$H23))
data$H24nF<-as.numeric(as.character(data$H24))
data$H25nF<-as.numeric(as.character(data$H25))
data$H26nF<-6-as.numeric(as.character(data$H26))
data$H27nF<-as.numeric(as.character(data$H27))
data$H28nF<-6-as.numeric(as.character(data$H28))
data$H29nF<-as.numeric(as.character(data$H29))
data$H30nF<-6-as.numeric(as.character(data$H30))
data$H31nF<-6-as.numeric(as.character(data$H31))
data$H32nF<-6-as.numeric(as.character(data$H32))
data$H33nF<-as.numeric(as.character(data$H33))
data$H34nF<-as.numeric(as.character(data$H34))
data$H35nF<-6-as.numeric(as.character(data$H35))
data$H36nF<-as.numeric(as.character(data$H36))
data$H37nF<-as.numeric(as.character(data$H37))
data$H38nF<-as.numeric(as.character(data$H38))
data$H39nF<-as.numeric(as.character(data$H39))
data$H40nF<-as.numeric(as.character(data$H40))
data$H41nF<-6-as.numeric(as.character(data$H41))
data$H42nF<-6-as.numeric(as.character(data$H42))
data$H43nF<-as.numeric(as.character(data$H43))
data$H44nF<-6-as.numeric(as.character(data$H44))
data$H45nF<-as.numeric(as.character(data$H45))
data$H46nF<-6-as.numeric(as.character(data$H46))
data$H47nF<-as.numeric(as.character(data$H47))
data$H48nF<-6-as.numeric(as.character(data$H48))
data$H49nF<-6-as.numeric(as.character(data$H49))
data$H50nF<-as.numeric(as.character(data$H50))
data$H51nF<-as.numeric(as.character(data$H51))
data$H52nF<-6-as.numeric(as.character(data$H52))
data$H53nF<-6-as.numeric(as.character(data$H53))
data$H54nF<-as.numeric(as.character(data$H54))
data$H55nF<-6-as.numeric(as.character(data$H55))
data$H56nF<-6-as.numeric(as.character(data$H56))
data$H57nF<-6-as.numeric(as.character(data$H57))
data$H58nF<-as.numeric(as.character(data$H58))
data$H59nF<-6-as.numeric(as.character(data$H59))
data$H60nF<-6-as.numeric(as.character(data$H60))

data$pers.h.sincerity = ((data$H6nF + data$H54nF + data$H30nF)/3) 
data$pers.h.fairness = ((data$H12nF + data$H36nF + data$H60nF)/3) 
data$pers.h.greedavoidance = ((data$H18nF + data$H42nF)/2) 
data$pers.h.modesty = ((data$H24nF + data$H48nF)/2)
data$pers.h = ((data$H6nF + data$H54nF + data$H30nF + data$H12nF + data$H36nF + data$H60nF + data$H18nF + data$H42nF + data$H24nF + data$H48nF)/10) 

data$pers.e.fearfulness = ((data$H5nF + data$H29nF + data$H53nF)/3)
data$pers.e.anxiety = ((data$H11nF + data$H35nF)/2)
data$pers.e.dependence = ((data$H17nF + data$H41nF)/2) 
data$pers.e.sentimentality = ((data$H23nF + data$H47nF + data$H59nF)/3) 
data$pers.e = ((data$H5nF + data$H29nF + data$H53nF + data$H11nF + data$H35nF + data$H17nF + data$H41nF + data$H23nF + data$H47nF + data$H59nF)/10)

data$pers.x.socialselfesteem = ((data$H4nF + data$H28nF + data$H52nF)/3)
data$pers.x.socialboldness = ((data$H10nF + data$H34nF + data$H58nF)/3) 
data$pers.x.sociability = ((data$H16nF + data$H40nF)/2)
data$pers.x.liveliness = ((data$H22nF + data$H46nF)/2) 
data$pers.x = ((data$H4nF + data$H28nF + data$H52nF + data$H10nF + data$H34nF + data$H58nF + data$H16nF + data$H40nF + data$H22nF + data$H46nF)/10)

data$pers.a.forgiveness = ((data$H3nF + data$H27nF)/2) 
data$pers.a.gentleness = ((data$H9nF + data$H33nF + data$H51nF)/3) 
data$pers.a.flexibility = ((data$H15nF + data$H39nF + data$H57nF)/3) 
data$pers.a.patience = ((data$H21nF + data$H45nF)/2) 
data$pers.a = ((data$H3nF + data$H27nF + data$H9nF + data$H33nF + data$H51nF + data$H15nF + data$H39nF + data$H57nF + data$H21nF + data$H45nF)/10) 

data$pers.c.organization = ((data$H2nF + data$H26nF)/2) 
data$pers.c.diligence = ((data$H8nF + data$H32nF)/2) 
data$pers.c.perfectionism = ((data$H14nF + data$H38nF + data$H50nF)/3) 
data$pers.c.prudence = ((data$H20nF + data$H44nF + data$H56nF)/3) 
data$pers.c = ((data$H2nF + data$H26nF + data$H8nF + data$H32nF + data$H14nF + data$H38nF + data$H50nF + data$H20nF + data$H44nF + data$H56nF)/10) 

data$pers.o.aestheticappreciation = ((data$H1nF + data$H25nF)/2) 
data$pers.o.inquisitiveness = ((data$H7nF + data$H31nF)/2) 
data$pers.o.creativity = ((data$H13nF + data$H37nF + data$H49nF)/3) 
data$pers.o.unconventionality = ((data$H19nF + data$H43nF + data$H55nF)/3) 
data$pers.o = ((data$H1nF + data$H25nF + data$H7nF + data$H31nF + data$H13nF + data$H37nF + data$H49nF + data$H19nF + data$H43nF + data$H55nF)/10) 

data$H1nS<-6-as.numeric(as.character(data$Q4486))
data$H2nS<-as.numeric(as.character(data$Q4487))
data$H3nS<-as.numeric(as.character(data$Q4488))
data$H4nS<-as.numeric(as.character(data$Q4489))
data$H5nS<-as.numeric(as.character(data$Q4490))
data$H6nS<-as.numeric(as.character(data$Q4491))
data$H7nS<-as.numeric(as.character(data$Q4492))
data$H8nS<-as.numeric(as.character(data$Q4493))
data$H9nS<-6-as.numeric(as.character(data$Q4494))
data$H10nS<-6-as.numeric(as.character(data$Q4495))
data$H11nS<-as.numeric(as.character(data$Q4496))
data$H12nS<-6-as.numeric(as.character(data$Q4497))
data$H13nS<-as.numeric(as.character(data$Q4498))
data$H14nS<-6-as.numeric(as.character(data$Q4499))
data$H15nS<-6-as.numeric(as.character(data$Q4500))
data$H16nS<-as.numeric(as.character(data$Q4501))
data$H17nS<-as.numeric(as.character(data$Q4502))
data$H18nS<-as.numeric(as.character(data$Q4503))
data$H19nS<-6-as.numeric(as.character(data$Q4504))
data$H20nS<-6-as.numeric(as.character(data$Q4505))
data$H21nS<-6-as.numeric(as.character(data$Q4506))
data$H22nS<-as.numeric(as.character(data$Q4507))
data$H23nS<-as.numeric(as.character(data$Q4508))
data$H24nS<-as.numeric(as.character(data$Q4509))
data$H25nS<-as.numeric(as.character(data$Q4510))
data$H26nS<-6-as.numeric(as.character(data$Q4511))
data$H27nS<-as.numeric(as.character(data$Q4512))
data$H28nS<-6-as.numeric(as.character(data$Q4513))
data$H29nS<-as.numeric(as.character(data$Q4514))
data$H30nS<-6-as.numeric(as.character(data$Q4515))
data$H31nS<-6-as.numeric(as.character(data$Q4516))
data$H32nS<-6-as.numeric(as.character(data$Q4517))
data$H33nS<-as.numeric(as.character(data$Q4518))
data$H34nS<-as.numeric(as.character(data$Q4519))
data$H35nS<-6-as.numeric(as.character(data$Q4520))
data$H36nS<-as.numeric(as.character(data$Q4521))
data$H37nS<-as.numeric(as.character(data$Q4522))
data$H38nS<-as.numeric(as.character(data$Q4523))
data$H39nS<-as.numeric(as.character(data$Q4524))
data$H40nS<-as.numeric(as.character(data$Q4525))
data$H41nS<-6-as.numeric(as.character(data$Q4526))
data$H42nS<-6-as.numeric(as.character(data$Q4527))
data$H43nS<-as.numeric(as.character(data$Q4528))
data$H44nS<-6-as.numeric(as.character(data$Q4529))
data$H45nS<-as.numeric(as.character(data$Q4530))
data$H46nS<-6-as.numeric(as.character(data$Q4531))
data$H47nS<-as.numeric(as.character(data$Q4532))
data$H48nS<-6-as.numeric(as.character(data$Q4533))
data$H49nS<-6-as.numeric(as.character(data$Q4534))
data$H50nS<-as.numeric(as.character(data$Q4535))
data$H51nS<-as.numeric(as.character(data$Q4536))
data$H52nS<-6-as.numeric(as.character(data$Q4537))
data$H53nS<-6-as.numeric(as.character(data$Q4538))
data$H54nS<-as.numeric(as.character(data$Q4539))
data$H55nS<-6-as.numeric(as.character(data$Q4540))
data$H56nS<-6-as.numeric(as.character(data$Q4541))
data$H57nS<-6-as.numeric(as.character(data$Q4542))
data$H58nS<-as.numeric(as.character(data$Q4543))
data$H59nS<-6-as.numeric(as.character(data$Q4544))
data$H60nS<-6-as.numeric(as.character(data$Q4545))

for (i in 1:60) {
  eval(parse(text=paste("data$H",i,"n<-rowSums(cbind(data$H",i,"nF, data$H",i,"nS),na.rm=TRUE)",sep="")))
  eval(parse(text=paste("data$H",i,"n[data$H",i,"n=='0']<-NA",sep="")))
}

##Social Dominance Orientation##

data$S1n<-as.numeric(paste(data$S1))
data$S2n<-as.numeric(paste(data$S2))
data$S3n<-6-as.numeric(paste(data$S3))
data$S4n<-6-as.numeric(paste(data$S4))
data$S5n<-6-as.numeric(paste(data$S5))
data$S6n<-as.numeric(paste(data$S6))
data$S7n<-as.numeric(paste(data$S7))
data$S8n<-6-as.numeric(paste(data$S8))

data$sdo.dominance<-(data$S7n + data$S2n + data$S3n + data$S5n)/4
data$sdo.antiegalitarianism<-(data$S1n + data$S6n + data$S4n + data$S8n)/4

data$sdo<-(data$S1n + data$S2n + data$S3n + data$S4n + data$S5n + data$S6n + data$S7n + data$S8n)/8

##Dark Triad##

data$T1n<-as.numeric(paste(data$T1))
data$T2n<-6-as.numeric(paste(data$T2))
data$T3n<-as.numeric(paste(data$T3))
data$T4n<-as.numeric(paste(data$T4))
data$T5n<-as.numeric(paste(data$T5))
data$T6n<-as.numeric(paste(data$T6))
data$T7n<-as.numeric(paste(data$T7))
data$T8n<-6-as.numeric(paste(data$T8))
data$T9n<-as.numeric(paste(data$T9))
data$T10n<-as.numeric(paste(data$T10))
data$T11n<-as.numeric(paste(data$T11))
data$T12n<-as.numeric(paste(data$T12))
data$T13n<-as.numeric(paste(data$T13))
data$T14n<-as.numeric(paste(data$T14))
data$T15n<-as.numeric(paste(data$T15))
data$T16n<-as.numeric(paste(data$T16))
data$T17n<-as.numeric(paste(data$T17))
data$T18n<-as.numeric(paste(data$T18))
data$T19n<-as.numeric(paste(data$T19))
data$T20n<-as.numeric(paste(data$T20))
data$T21n<-as.numeric(paste(data$T21))
data$T22n<-6-as.numeric(paste(data$T22))
data$T23n<-6-as.numeric(paste(data$T23))
data$T24n<-as.numeric(paste(data$T24))
data$T25n<-6-as.numeric(paste(data$T25))
data$T26n<-as.numeric(paste(data$T26))
data$T27n<-as.numeric(paste(data$T27))

data$sd3.machiavellianism <- (data$T12n + data$T18n + data$T19n + data$T14n + data$T9n + data$T5n + data$T16n + data$T1n + data$T7n)/9
data$sd3.narcissism <- (data$T15n + data$T25n + data$T27n + data$T6n + data$T20n + data$T22n + data$T10n + data$T2n + data$T3n)/9
data$sd3.psychopathy <- (data$T21n + data$T8n + data$T11n + data$T26n + data$T13n + data$T4n + data$T23n + data$T24n + data$T17n)/9

##TIPI##

data$tipi1.n<-as.numeric(paste(data$F1_1))
data$tipi2.n<-6-as.numeric(paste(data$F1_2))
data$tipi3.n<-as.numeric(paste(data$F1_3))
data$tipi4.n<-6-as.numeric(paste(data$F1_4))
data$tipi5.n<-as.numeric(paste(data$F1_5))
data$tipi6.n<-6-as.numeric(paste(data$F1_6))
data$tipi7.n<-as.numeric(paste(data$F1_7))
data$tipi8.n<-6-as.numeric(paste(data$F1_8))
data$tipi9.n<-as.numeric(paste(data$F1_9))
data$tipi10.n<-6-as.numeric(paste(data$F1_10))

data$tipi.pers.x <- (data$tipi1.n+data$tipi6.n)/2  
data$tipi.pers.a <- (data$tipi2.n+data$tipi7.n)/2
data$tipi.pers.c <- (data$tipi3.n+data$tipi8.n)/2
data$tipi.pers.e <- (data$tipi4.n+data$tipi9.n)/2
data$tipi.pers.o <- (data$tipi5.n+data$tipi10.n)/2

##Political Ideology##
 
data$C2an<-as.numeric(paste(data$C2a)) 
data$C2bn<-6-as.numeric(paste(data$C2b))
data$C2cn<-6-as.numeric(paste(data$C2c))
data$C2dn<-6-as.numeric(paste(data$C2d))
data$C2en<-6-as.numeric(paste(data$C2e))
data$C2fn<-6-as.numeric(paste(data$C2f))
data$C2gn<-6-as.numeric(paste(data$C2g))
data$C2hn<-as.numeric(paste(data$C2h))
data$C2in<-6-as.numeric(paste(data$C2i))
data$C2jn<-6-as.numeric(paste(data$C2j))
data$C2kn<-as.numeric(paste(data$C2k))
data$C2ln<-6-as.numeric(paste(data$C2l))

data$C2an[data$C2an=="4"]<-3
data$C2an[data$C2an=="5"]<-4
data$C2bn[data$C2bn=="4"]<-3
data$C2bn[data$C2bn=="5"]<-4
data$C2cn[data$C2cn=="4"]<-3
data$C2cn[data$C2cn=="5"]<-4
data$C2dn[data$C2dn=="4"]<-3
data$C2dn[data$C2dn=="5"]<-4
data$C2en[data$C2en=="4"]<-3
data$C2en[data$C2en=="5"]<-4
data$C2fn[data$C2fn=="4"]<-3
data$C2fn[data$C2fn=="5"]<-4
data$C2gn[data$C2gn=="4"]<-3
data$C2gn[data$C2gn=="5"]<-4
data$C2hn[data$C2hn=="4"]<-3
data$C2hn[data$C2hn=="5"]<-4
data$C2in[data$C2in=="4"]<-3
data$C2in[data$C2in=="5"]<-4
data$C2jn[data$C2jn=="4"]<-3
data$C2jn[data$C2jn=="5"]<-4
data$C2kn[data$C2kn=="4"]<-3
data$C2kn[data$C2kn=="5"]<-4
data$C2ln[data$C2ln=="4"]<-3
data$C2ln[data$C2ln=="5"]<-4

data$ideology.freemarket <- (data$C2an + data$C2bn + data$C2fn + data$C2gn + data$C2hn +  data$C2in + data$C2jn)  / 7   
data$ideology.democracy <- (data$C2cn + data$C2dn + data$C2en + data$C2kn + data$C2ln)  / 5   
summary(data$ideology.democracy)

##Ravens Progressive Matrices##

data$r1.correct<-NA
data$r1.correct[data$R1=="18"]<-1

data$r2.correct<-NA
data$r2.correct[data$R2=="1"]<-0
data$r2.correct[data$R2=="2"]<-0
data$r2.correct[data$R2=="3"]<-0
data$r2.correct[data$R2=="4"]<-1
data$r2.correct[data$R2=="5"]<-0
data$r2.correct[data$R2=="6"]<-0
data$r2.correct[data$R2=="7"]<-0
data$r2.correct[data$R2=="8"]<-0

data$r3.correct<-NA
data$r3.correct[data$R3=="1"]<-0
data$r3.correct[data$R3=="2"]<-0
data$r3.correct[data$R3=="3"]<-0
data$r3.correct[data$R3=="4"]<-0
data$r3.correct[data$R3=="5"]<-0
data$r3.correct[data$R3=="6"]<-1
data$r3.correct[data$R3=="7"]<-0
data$r3.correct[data$R3=="8"]<-0

data$r4.correct<-NA
data$r4.correct[data$R4=="1"]<-0
data$r4.correct[data$R4=="2"]<-1
data$r4.correct[data$R4=="3"]<-0
data$r4.correct[data$R4=="4"]<-0
data$r4.correct[data$R4=="5"]<-0
data$r4.correct[data$R4=="6"]<-0
data$r4.correct[data$R4=="7"]<-0
data$r4.correct[data$R4=="8"]<-0

data$r5.correct<-NA
data$r5.correct[data$R5=="1"]<-0
data$r5.correct[data$R5=="2"]<-0
data$r5.correct[data$R5=="3"]<-1
data$r5.correct[data$R5=="4"]<-0
data$r5.correct[data$R5=="5"]<-0
data$r5.correct[data$R5=="6"]<-0
data$r5.correct[data$R5=="7"]<-0
data$r5.correct[data$R5=="8"]<-0

data$r6.correct<-NA
data$r6.correct[data$R6=="1"]<-1
data$r6.correct[data$R6=="2"]<-0
data$r6.correct[data$R6=="3"]<-0
data$r6.correct[data$R6=="4"]<-0
data$r6.correct[data$R6=="5"]<-0
data$r6.correct[data$R6=="6"]<-0
data$r6.correct[data$R6=="7"]<-0
data$r6.correct[data$R6=="8"]<-0

summary(data$r1.correct)
summary(data$r2.correct)
summary(data$r3.correct)
summary(data$r4.correct)
summary(data$r5.correct)
summary(data$r6.correct)

data$rtotal.correct<- data$r2.correct + data$r3.correct + data$r4.correct + data$r5.correct + data$r6.correct

###MULTIPLE IMPUTATION###

names(data)
data.mi<- data.frame(cbind(data$id, data$sat.central, data$selfcens, data$H1n, data$H2n, data$H3n, data$H4n, data$H5n, data$H6n, data$H7n, data$H8n, data$H9n, data$H10n, data$H11n, data$H12n, data$H13n, data$H14n, data$H15n, data$H16n, data$H17n, data$H18n, data$H19n, data$H20n, data$H21n, data$H22n, data$H23n, data$H24n, data$H25n, data$H26n, data$H27n, data$H28n, data$H29n, data$H30n, data$H31n, data$H32n, data$H33n, data$H34n, data$H35n, data$H36n, data$H37n, data$H38n, data$H39n, data$H40n, data$H41n, data$H42n, data$H43n, data$H44n, data$H45n, data$H46n, data$H47n, data$H48n, data$H49n, data$H50n, data$H51n, data$H52n, data$H53n, data$H54n, data$H55n, data$H56n, data$H57n, data$H58n, data$H59n, data$H60n, data$C2an, data$C2bn, data$C2cn, data$C2dn, data$C2en, data$C2fn, data$C2gn, data$C2hn, data$C2in, data$C2jn, data$C2kn, data$C2ln, data$female, data$minority, data$age, data$lowed, data$ccp, data$party.mem, data$part.meeting, data$part.opinleaders, data$part.opinmedia, data$part.voted, data$part.protest, data$part.onlinecrit, data$part.onlinediscprotest, data$part.petition, data$S1n,data$S2n,data$S3n,data$S4n,data$S5n,data$S6n,data$S7n,data$S8n,data$T1n,data$T2n,data$T3n,data$T4n,data$T5n,data$T6n,data$T7n,data$T8n,data$T9n,data$T10n,data$T11n,data$T12n,data$T13n,data$T14n,data$T15n,data$T16n,data$T17n,data$T18n,data$T19n,data$T20n,data$T21n,data$T22n,data$T23n,data$T24n,data$T25n,data$T26n,data$T27n,data$rtotal.correct,data$tipi1.n,data$tipi2.n,data$tipi3.n,data$tipi4.n,data$tipi5.n,data$tipi6.n,data$tipi7.n,data$tipi8.n,data$tipi9.n,data$tipi10.n))      
colnames(data.mi) <-c("id", "sat.central","selfcens","H1n", "H2n", "H3n", "H4n", "H5n", "H6n", "H7n", "H8n", "H9n", "H10n", "H11n", "H12n", "H13n", "H14n", "H15n", "H16n", "H17n", "H18n", "H19n", "H20n", "H21n", "H22n", "H23n", "H24n", "H25n", "H26n", "H27n", "H28n", "H29n", "H30n", "H31n", "H32n", "H33n", "H34n", "H35n", "H36n", "H37n", "H38n", "H39n", "H40n", "H41n", "H42n", "H43n", "H44n", "H45n", "H46n", "H47n", "H48n", "H49n", "H50n", "H51n", "H52n", "H53n", "H54n", "H55n", "H56n", "H57n", "H58n", "H59n", "H60n", "C2an", "C2bn", "C2cn", "C2dn", "C2en", "C2fn", "C2gn", "C2hn", "C2in", "C2jn", "C2kn", "C2ln", "female", "minority", "age", "lowed", "ccp", "party.mem", "part.meeting", "part.opinleaders", "part.opinmedia", "part.voted", "part.protest", "part.onlinecrit", "part.onlinediscprotest", "part.petition","S1n","S2n","S3n","S4n","S5n","S6n","S7n","S8n","T1n","T2n","T3n","T4n","T5n","T6n","T7n","T8n","T9n","T10n","T11n","T12n","T13n","T14n","T15n","T16n","T17n","T18n","T19n","T20n","T21n","T22n","T23n","T24n","T25n","T26n","T27n","rtotal.correct","tipi1.n","tipi2.n","tipi3.n","tipi4.n","tipi5.n","tipi6.n","tipi7.n","tipi8.n","tipi9.n","tipi10.n")
summary(data.mi)

data.mi$sat.central<-as.numeric(as.character(data.mi$sat.central))

data.mi$rtotal.correct<-as.numeric(as.character(data.mi$rtotal.correct))

data.mi$H1n<-as.numeric(as.character(data.mi$H1n))
data.mi$H2n<-as.numeric(as.character(data.mi$H2n))
data.mi$H3n<-as.numeric(as.character(data.mi$H3n))
data.mi$H4n<-as.numeric(as.character(data.mi$H4n))
data.mi$H5n<-as.numeric(as.character(data.mi$H5n))
data.mi$H6n<-as.numeric(as.character(data.mi$H6n))
data.mi$H7n<-as.numeric(as.character(data.mi$H7n))
data.mi$H8n<-as.numeric(as.character(data.mi$H8n))
data.mi$H9n<-as.numeric(as.character(data.mi$H9n))
data.mi$H10n<-as.numeric(as.character(data.mi$H10n))
data.mi$H11n<-as.numeric(as.character(data.mi$H11n))
data.mi$H12n<-as.numeric(as.character(data.mi$H12n))
data.mi$H13n<-as.numeric(as.character(data.mi$H13n))
data.mi$H14n<-as.numeric(as.character(data.mi$H14n))
data.mi$H15n<-as.numeric(as.character(data.mi$H15n))
data.mi$H16n<-as.numeric(as.character(data.mi$H16n))
data.mi$H17n<-as.numeric(as.character(data.mi$H17n))
data.mi$H18n<-as.numeric(as.character(data.mi$H18n))
data.mi$H19n<-as.numeric(as.character(data.mi$H19n))
data.mi$H20n<-as.numeric(as.character(data.mi$H20n))
data.mi$H21n<-as.numeric(as.character(data.mi$H21n))
data.mi$H22n<-as.numeric(as.character(data.mi$H22n))
data.mi$H23n<-as.numeric(as.character(data.mi$H23n))
data.mi$H24n<-as.numeric(as.character(data.mi$H24n))
data.mi$H25n<-as.numeric(as.character(data.mi$H25n))
data.mi$H26n<-as.numeric(as.character(data.mi$H26n))
data.mi$H27n<-as.numeric(as.character(data.mi$H27n))
data.mi$H28n<-as.numeric(as.character(data.mi$H28n))
data.mi$H29n<-as.numeric(as.character(data.mi$H29n))
data.mi$H30n<-as.numeric(as.character(data.mi$H30n))
data.mi$H31n<-as.numeric(as.character(data.mi$H31n))
data.mi$H32n<-as.numeric(as.character(data.mi$H32n))
data.mi$H33n<-as.numeric(as.character(data.mi$H33n))
data.mi$H34n<-as.numeric(as.character(data.mi$H34n))
data.mi$H35n<-as.numeric(as.character(data.mi$H35n))
data.mi$H36n<-as.numeric(as.character(data.mi$H36n))
data.mi$H37n<-as.numeric(as.character(data.mi$H37n))
data.mi$H38n<-as.numeric(as.character(data.mi$H38n))
data.mi$H39n<-as.numeric(as.character(data.mi$H39n))
data.mi$H40n<-as.numeric(as.character(data.mi$H40n))
data.mi$H41n<-as.numeric(as.character(data.mi$H41n))
data.mi$H42n<-as.numeric(as.character(data.mi$H42n))
data.mi$H43n<-as.numeric(as.character(data.mi$H43n))
data.mi$H44n<-as.numeric(as.character(data.mi$H44n))
data.mi$H45n<-as.numeric(as.character(data.mi$H45n))
data.mi$H46n<-as.numeric(as.character(data.mi$H46n))
data.mi$H47n<-as.numeric(as.character(data.mi$H47n))
data.mi$H48n<-as.numeric(as.character(data.mi$H48n))
data.mi$H49n<-as.numeric(as.character(data.mi$H49n))
data.mi$H50n<-as.numeric(as.character(data.mi$H50n))
data.mi$H51n<-as.numeric(as.character(data.mi$H51n))
data.mi$H52n<-as.numeric(as.character(data.mi$H52n))
data.mi$H53n<-as.numeric(as.character(data.mi$H53n))
data.mi$H54n<-as.numeric(as.character(data.mi$H54n))
data.mi$H55n<-as.numeric(as.character(data.mi$H55n))
data.mi$H56n<-as.numeric(as.character(data.mi$H56n))
data.mi$H57n<-as.numeric(as.character(data.mi$H57n))
data.mi$H58n<-as.numeric(as.character(data.mi$H58n))
data.mi$H59n<-as.numeric(as.character(data.mi$H59n))
data.mi$H60n<-as.numeric(as.character(data.mi$H60n))

data.mi$C2an<-as.numeric(as.character(data.mi$C2an))
data.mi$C2bn<-as.numeric(as.character(data.mi$C2bn))
data.mi$C2cn<-as.numeric(as.character(data.mi$C2cn))
data.mi$C2dn<-as.numeric(as.character(data.mi$C2dn))
data.mi$C2en<-as.numeric(as.character(data.mi$C2en))
data.mi$C2fn<-as.numeric(as.character(data.mi$C2fn))
data.mi$C2gn<-as.numeric(as.character(data.mi$C2gn))
data.mi$C2hn<-as.numeric(as.character(data.mi$C2hn))
data.mi$C2in<-as.numeric(as.character(data.mi$C2in))
data.mi$C2jn<-as.numeric(as.character(data.mi$C2jn))
data.mi$C2kn<-as.numeric(as.character(data.mi$C2kn))
data.mi$C2ln<-as.numeric(as.character(data.mi$C2ln))

data.mi$age<-as.numeric(as.character(data.mi$age))

data.mi$S1n<-as.numeric(as.character(data.mi$S1n ))
data.mi$S2n<-as.numeric(as.character(data.mi$S2n ))
data.mi$S3n<-as.numeric(as.character(data.mi$S3n ))
data.mi$S4n<-as.numeric(as.character(data.mi$S4n ))
data.mi$S5n<-as.numeric(as.character(data.mi$S5n ))
data.mi$S6n<-as.numeric(as.character(data.mi$S6n ))
data.mi$S7n<-as.numeric(as.character(data.mi$S7n ))
data.mi$S8n<-as.numeric(as.character(data.mi$S8n ))
data.mi$T1n<-as.numeric(as.character(data.mi$T1n ))
data.mi$T2n<-as.numeric(as.character(data.mi$T2n ))
data.mi$T3n<-as.numeric(as.character(data.mi$T3n ))
data.mi$T4n<-as.numeric(as.character(data.mi$T4n ))
data.mi$T5n<-as.numeric(as.character(data.mi$T5n ))
data.mi$T6n<-as.numeric(as.character(data.mi$T6n ))
data.mi$T7n<-as.numeric(as.character(data.mi$T7n ))
data.mi$T8n<-as.numeric(as.character(data.mi$T8n ))
data.mi$T9n<-as.numeric(as.character(data.mi$T9n ))
data.mi$T10n<-as.numeric(as.character(data.mi$T10n ))
data.mi$T11n<-as.numeric(as.character(data.mi$T11n ))
data.mi$T12n<-as.numeric(as.character(data.mi$T12n ))
data.mi$T13n<-as.numeric(as.character(data.mi$T13n ))
data.mi$T14n<-as.numeric(as.character(data.mi$T14n ))
data.mi$T15n<-as.numeric(as.character(data.mi$T15n ))
data.mi$T16n<-as.numeric(as.character(data.mi$T16n ))
data.mi$T17n<-as.numeric(as.character(data.mi$T17n ))
data.mi$T18n<-as.numeric(as.character(data.mi$T18n ))
data.mi$T19n<-as.numeric(as.character(data.mi$T19n ))
data.mi$T20n<-as.numeric(as.character(data.mi$T20n ))
data.mi$T21n<-as.numeric(as.character(data.mi$T21n ))
data.mi$T22n<-as.numeric(as.character(data.mi$T22n ))
data.mi$T23n<-as.numeric(as.character(data.mi$T23n ))
data.mi$T24n<-as.numeric(as.character(data.mi$T24n ))
data.mi$T25n<-as.numeric(as.character(data.mi$T25n ))
data.mi$T26n<-as.numeric(as.character(data.mi$T26n ))
data.mi$T27n<-as.numeric(as.character(data.mi$T27n ))

data.mi$rtotal.correct<-as.numeric(as.character(data.mi$rtotal.correct ))

data.mi$tipi1.n<-as.numeric(as.character(data.mi$tipi1.n))
data.mi$tipi2.n<-as.numeric(as.character(data.mi$tipi2.n))
data.mi$tipi3.n<-as.numeric(as.character(data.mi$tipi3.n))
data.mi$tipi4.n<-as.numeric(as.character(data.mi$tipi4.n))
data.mi$tipi5.n<-as.numeric(as.character(data.mi$tipi5.n))
data.mi$tipi6.n<-as.numeric(as.character(data.mi$tipi6.n))
data.mi$tipi7.n<-as.numeric(as.character(data.mi$tipi7.n))
data.mi$tipi8.n<-as.numeric(as.character(data.mi$tipi8.n))
data.mi$tipi9.n<-as.numeric(as.character(data.mi$tipi9.n))
data.mi$tipi10.n<-as.numeric(as.character(data.mi$tipi10.n))

set.seed(1234)
a.out <- amelia(data.mi, p2s=1, m = 50, idvars = c("id","party.mem"), noms=c("selfcens","female", "minority", "lowed", "ccp", "part.meeting", "part.opinleaders", "part.opinmedia", "part.voted", "part.protest", "part.onlinecrit", "part.onlinediscprotest", "part.petition"), ords = c("sat.central","rtotal.correct","H1n", "H2n", "H3n", "H4n", "H5n", "H6n", "H7n", "H8n", "H9n", "H10n", "H11n", "H12n", "H13n", "H14n", "H15n", "H16n", "H17n", "H18n", "H19n", "H20n", "H21n", "H22n", "H23n", "H24n", "H25n", "H26n", "H27n", "H28n", "H29n", "H30n", "H31n", "H32n", "H33n", "H34n", "H35n", "H36n", "H37n", "H38n", "H39n", "H40n", "H41n", "H42n", "H43n", "H44n", "H45n", "H46n", "H47n", "H48n", "H49n", "H50n", "H51n", "H52n", "H53n", "H54n", "H55n", "H56n", "H57n", "H58n", "H59n", "H60n", "C2an", "C2bn", "C2cn", "C2dn", "C2en", "C2fn", "C2gn", "C2hn", "C2in", "C2jn", "C2kn", "C2ln", "age","S1n","S2n","S3n","S4n","S5n","S6n","S7n","S8n","T1n","T2n","T3n","T4n","T5n","T6n","T7n","T8n","T9n","T10n","T11n","T12n","T13n","T14n","T15n","T16n","T17n","T18n","T19n","T20n","T21n","T22n","T23n","T24n","T25n","T26n","T27n","tipi1.n","tipi2.n","tipi3.n","tipi4.n","tipi5.n","tipi6.n","tipi7.n","tipi8.n","tipi9.n","tipi10.n"))
a.out
write.amelia(obj = a.out, file.stem = "data.m")

###CREATE VARIABLES ACROSS IMPUTED DATASETS###

a.out<-transform(a.out, pers.h.sincerity = ((H6n + H54n + H30n)/3)) 
a.out<-transform(a.out, pers.h.fairness = ((H12n + H36n + H60n)/3)) 
a.out<-transform(a.out, pers.h.greedavoidance = ((H18n + H42n)/2)) 
a.out<-transform(a.out, pers.h.modesty = ((H24n + H48n)/2)) 
a.out<-transform(a.out, pers.h = ((H6n + H54n + H30n + H12n + H36n + H60n + H18n + H42n + H24n + H48n)/10)) 

a.out<-transform(a.out, pers.e.fearfulness = ((H5n + H29n + H53n)/3)) 
a.out<-transform(a.out, pers.e.anxiety = ((H11n + H35n)/2)) 
a.out<-transform(a.out, pers.e.dependence = ((H17n + H41n)/2)) 
a.out<-transform(a.out, pers.e.sentimentality = ((H23n + H47n + H59n)/3)) 
a.out<-transform(a.out, pers.e = ((H5n + H29n + H53n + H11n + H35n + H17n + H41n + H23n + H47n + H59n)/10)) 

a.out<-transform(a.out, pers.x.socialselfesteem = ((H4n + H28n + H52n)/3)) 
a.out<-transform(a.out, pers.x.socialboldness = ((H10n + H34n + H58n)/3)) 
a.out<-transform(a.out, pers.x.sociability = ((H16n + H40n)/2)) 
a.out<-transform(a.out, pers.x.liveliness = ((H22n + H46n)/2)) 
a.out<-transform(a.out, pers.x = ((H4n + H28n + H52n + H10n + H34n + H58n + H16n + H40n + H22n + H46n)/10)) 

a.out<-transform(a.out, pers.a.forgiveness = ((H3n + H27n)/2)) 
a.out<-transform(a.out, pers.a.gentleness = ((H9n + H33n + H51n)/3)) 
a.out<-transform(a.out, pers.a.flexibility = ((H15n + H39n + H57n)/3)) 
a.out<-transform(a.out, pers.a.patience = ((H21n + H45n)/2)) 
a.out<-transform(a.out, pers.a = ((H3n + H27n + H9n + H33n + H51n + H15n + H39n + H57n + H21n + H45n)/10)) 

a.out<-transform(a.out, pers.c.organization = ((H2n + H26n)/2)) 
a.out<-transform(a.out, pers.c.diligence = ((H8n + H32n)/2)) 
a.out<-transform(a.out, pers.c.perfectionism = ((H14n + H38n + H50n)/3)) 
a.out<-transform(a.out, pers.c.prudence = ((H20n + H44n + H56n)/3)) 
a.out<-transform(a.out, pers.c = ((H2n + H26n + H8n + H32n + H14n + H38n + H50n + H20n + H44n + H56n)/10)) 

a.out<-transform(a.out, pers.o.aestheticappreciation = ((H1n + H25n)/2)) 
a.out<-transform(a.out, pers.o.inquisitiveness = ((H7n + H31n)/2)) 
a.out<-transform(a.out, pers.o.creativity = ((H13n + H37n + H49n)/3)) 
a.out<-transform(a.out, pers.o.unconventionality = ((H19n + H43n + H55n)/3)) 
a.out<-transform(a.out, pers.o = ((H1n + H25n + H7n + H31n + H13n + H37n + H49n + H19n + H43n + H55n)/10)) 

a.out<-transform(a.out, tipi.pers.x = ((data$tipi1.n+data$tipi6.n)/2)) 
a.out<-transform(a.out, tipi.pers.a = ((data$tipi2.n+data$tipi7.n)/2)) 
a.out<-transform(a.out, tipi.pers.c = ((data$tipi3.n+data$tipi8.n)/2)) 
a.out<-transform(a.out, tipi.pers.e = ((data$tipi4.n+data$tipi9.n)/2)) 
a.out<-transform(a.out, tipi.pers.o = ((data$tipi5.n+data$tipi10.n)/2))

a.out<-transform(a.out, ideology.freemarket = ((C2an + C2bn + C2fn + C2gn + C2hn + C2in + C2jn)/7)) 
a.out<-transform(a.out, ideology.democracy = ((C2cn + C2dn + C2en + C2kn + C2ln)/5)) 

a.out<-transform(a.out, sd3.machiavellianism = ((T12n + T18n + T19n + T14n + T9n + T5n + T16n + T1n + T7n)/9)) 
a.out<-transform(a.out, sd3.narcissism = ((T15n + T25n + T27n + T6n + T20n + T22n + T10n + T2n + T3n)/9)) 
a.out<-transform(a.out, sd3.psychopathy = ((T21n + T8n + T11n + T26n + T13n + T4n + T23n + T24n + T17n)/9)) 

a.out<-transform(a.out, sdo.dominance = ((S7n + S2n + S3n + S5n)/4)) 
a.out<-transform(a.out, sdo.antiegalitarianism = ((S1n + S6n + S4n + S8n)/4)) 
a.out<-transform(a.out, sdo = ((S1n + S2n + S3n + S4n + S5n + S6n + S7n + S8n)/8)) 

a.out<-transform(a.out, part.inst = (as.numeric(as.character(part.meeting)) + as.numeric(as.character(part.opinleaders)) + as.numeric(as.character(part.opinmedia)) + as.numeric(as.character(part.voted)))) 
a.out<-transform(a.out, part.cont = (as.numeric(as.character(part.protest)) + as.numeric(as.character(part.onlinecrit)) + as.numeric(as.character(part.onlinediscprotest)) + as.numeric(as.character(part.petition))))
a.out<-transform(a.out, part.total = (as.numeric(as.character(part.meeting)) + as.numeric(as.character(part.opinleaders)) + as.numeric(as.character(part.opinmedia)) + as.numeric(as.character(part.voted)) + as.numeric(as.character(part.protest)) + as.numeric(as.character(part.onlinecrit)) + as.numeric(as.character(part.onlinediscprotest)) + as.numeric(as.character(part.petition))))
a.out<-transform(a.out, discontent=ifelse(sat.central<5,1,0))
a.out<-transform(a.out, discontent.alt=ifelse(sat.central<7,1,0))
a.out<-transform(a.out, discontent.dem=ifelse(ideology.democracy>2.9999,1,0))

###ANALYSIS###

#Figure: Distribution of Regime Support#

data.bar.cpt<-data.frame(ftable(data$sat.central))
colnames(data.bar.cpt)<-c("support","frequency")
data.bar.cpt$group<-"Supporter"
data.bar.cpt$group[data.bar.cpt$support=="4"]<-"Discontent"
data.bar.cpt$group[data.bar.cpt$support=="3"]<-"Discontent"
data.bar.cpt$group[data.bar.cpt$support=="2"]<-"Discontent"
data.bar.cpt$group[data.bar.cpt$support=="1"]<-"Discontent"
data.bar.cpt$group[data.bar.cpt$support=="0"]<-"Discontent"

write.csv(data.bar.cpt, "data.bar.cpt.csv")

pdf('fig-regsupport.pdf', width=5.25, height=3.5)
ggplot(data.bar.cpt, aes(x=support, y=frequency, colour=group, fill=group)) + geom_col(alpha=.5,width=.7) +theme_bw() + xlab("Satisfaction with Central Government") + ylab("Count")  +  geom_vline(xintercept = 5.5, size=.5, color="grey50",lty="dashed") + annotate("text", x=3, y = 150, label = "Discontents",color="grey20", size=3.75)  + annotate("text", x=3, y = 100, label = "n=106, 5.2%",color="grey20", size=3.65) + scale_color_manual(values=c("#fc8d62","grey50"),guide=FALSE, aesthetics = c("fill","color"))
dev.off()

#Figure: Personality and Regime Support#

a.mids <- miceadds::datlist2mids(a.out$imputations)

m1<-with(a.mids, lm(pers.h~discontent)) 
m2<-with(a.mids, lm(pers.h.sincerity~discontent)) 
m3<-with(a.mids, lm(pers.h.fairness~discontent)) 
m4<-with(a.mids, lm(pers.h.greedavoidance~discontent)) 
m5<-with(a.mids, lm(pers.h.modesty~discontent)) 
m6<-with(a.mids, lm(pers.e~discontent)) 
m7<-with(a.mids, lm(pers.e.fearfulness~discontent)) 
m8<-with(a.mids, lm(pers.e.anxiety~discontent)) 
m9<-with(a.mids, lm(pers.e.dependence~discontent)) 
m10<-with(a.mids, lm(pers.e.sentimentality~discontent)) 
m11<-with(a.mids, lm(pers.x~discontent)) 
m12<-with(a.mids, lm(pers.x.socialselfesteem~discontent)) 
m13<-with(a.mids, lm(pers.x.socialboldness~discontent)) 
m14<-with(a.mids, lm(pers.x.sociability~discontent)) 
m15<-with(a.mids, lm(pers.x.liveliness~discontent)) 
m16<-with(a.mids, lm(pers.a~discontent)) 
m17<-with(a.mids, lm(pers.a.forgiveness~discontent)) 
m18<-with(a.mids, lm(pers.a.gentleness~discontent)) 
m19<-with(a.mids, lm(pers.a.flexibility~discontent)) 
m20<-with(a.mids, lm(pers.a.patience~discontent)) 
m21<-with(a.mids, lm(pers.c~discontent)) 
m22<-with(a.mids, lm(pers.c.organization~discontent)) 
m23<-with(a.mids, lm(pers.c.diligence~discontent)) 
m24<-with(a.mids, lm(pers.c.perfectionism~discontent)) 
m25<-with(a.mids, lm(pers.c.prudence~discontent)) 
m26<-with(a.mids, lm(pers.o~discontent)) 
m27<-with(a.mids, lm(pers.o.aestheticappreciation~discontent)) 
m28<-with(a.mids, lm(pers.o.inquisitiveness~discontent)) 
m29<-with(a.mids, lm(pers.o.creativity~discontent)) 
m30<-with(a.mids, lm(pers.o.unconventionality~discontent)) 
m31<-with(a.mids, lm(sd3.machiavellianism~discontent)) 
m32<-with(a.mids, lm(sd3.narcissism~discontent)) 
m33<-with(a.mids, lm(sd3.psychopathy~discontent)) 
m34<-with(a.mids, lm(sdo.dominance~discontent)) 
m35<-with(a.mids, lm(sdo.antiegalitarianism~discontent)) 
m36<-with(a.mids, lm(sdo~discontent)) 
m37<-with(a.mids, lm(ideology.freemarket~discontent)) 
m38<-with(a.mids, lm(ideology.democracy~discontent)) 
m39<-with(a.mids, lm(rtotal.correct~discontent)) 
m40<-with(a.mids, lm(tipi.pers.e~discontent)) 
m41<-with(a.mids, lm(tipi.pers.x~discontent)) 
m42<-with(a.mids, lm(tipi.pers.a~discontent)) 
m43<-with(a.mids, lm(tipi.pers.c~discontent)) 
m44<-with(a.mids, lm(tipi.pers.o~discontent))

output <- matrix(data = NA, nrow=44, ncol=5)
output<-data.frame(output)
colnames(output)<-c("measure", "estimate","se")
output$measure<-rep(c("pers.h","pers.h.sincerity","pers.h.fairness","pers.h.greedavoidance","pers.h.modesty","pers.e","pers.e.fearfulness","pers.e.anxiety","pers.e.dependence","pers.e.sentimentality","pers.x","pers.x.socialselfesteem","pers.x.socialboldness","pers.x.sociability","pers.x.liveliness","pers.a","pers.a.forgiveness","pers.a.gentleness","pers.a.flexibility","pers.a.patience","pers.c","pers.c.organization","pers.c.diligence","pers.c.perfectionism","pers.c.prudence","pers.o","pers.o.aestheticappreciation","pers.o.inquisitiveness","pers.o.creativity","pers.o.unconventionality","sd3.machiavellianism","sd3.narcissism","sd3.psychopathy","sdo.dominance","sdo.antiegalitarianism","sdo","ideology.freemarket","ideology.democracy","rtotal.correct","tipi.pers.e","tipi.pers.x","tipi.pers.a","tipi.pers.c","tipi.pers.o"), times=1)
output$label<-rep(c("Honesty-Humility","Honesty-Humility - Sincerity","Honesty-Humility - Fairness","Honesty-Humility - Greed Avoidance","Honesty-Humility - Modesty","Emotionality","Emotionality - Fearfulness","Emotionality - Anxiety","Emotionality - Dependence","Emotionality - Sentimentality","eXtraversion","eXtraversion - Social Self Esteem","eXtraversion - Social Boldness","eXtraversion - Sociability","eXtraversion - Liveliness", "Agreeableness", "Agreeableness - Forgiveness","Agreeableness - Gentleness","Agreeableness - Flexibility","Agreeableness - Patience","Conscientiousness","Conscientiousness - Organization","Conscientiousness - Diligence","Conscientiousness - Perfectionism","Conscientiousness - Prudence","Openness","Openness - Aesthetic Appreciation","Openness - Inquisitiveness","Openness - Creativity","Openness - Unconventionality","Machiavellianism","Narcissism","Psychopathy","Dominance","Antiegalitarianism","Social Dominance Orientation","Economic Liberalism","Political Liberalism","IQ", "Emotionality","eXtraversion","Agreeableness","Conscientiousness","Openness to Experience"), times=1)
output$facet<-rep(c("H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","E. Emotionality","E. Emotionality","E. Emotionality","E. Emotionality","E. Emotionality","X. Extraversion","X. Extraversion","X. Extraversion","X. Extraversion","X. Extraversion","A. Agreeableness","A. Agreeableness","A. Agreeableness","A. Agreeableness","A. Agreeableness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","Dark Triad","Dark Triad","Dark Triad","SDO","SDO","SDO","Ideology","Ideology","IQ","E. Emotionality","X. Extraversion", "A. Agreeableness", "C. Conscientiousness", "O. Openness to Experience"), times=1)
output$facet = factor(output$facet,levels=c("H. Honesty-Humility", "E. Emotionality","X. Extraversion","A. Agreeableness","C. Conscientiousness","O. Openness to Experience","Dark Triad","SDO","IQ","Ideology"))
output$facet2<-rep(c("HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","Dark Triad","Dark Triad","Dark Triad","SDO","SDO","SDO","Ideology","Ideology","IQ","TIPI FFM","TIPI FFM", "TIPI FFM", "TIPI FFM", "TIPI FFM"), times=1)
output$facet2 = factor(output$facet2,levels=c("HEXACO", "TIPI FFM","Dark Triad", "SDO","IQ","Ideology"))

for (j in 1:44) {
  try(eval(parse(text=paste("output$coeff[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,2]",sep=""))))
  try(eval(parse(text=paste("output$se[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,3]",sep=""))))
}  

output$l95ci<-output$coeff-1.96*output$se
output$u95ci<-output$coeff+1.96*output$se

output$label<-c("honesty-humility","sincerity","fairness","greed avoidance","modesty","emotionality","fearfulness","anxiety","dependence","sentimentality","extraversion","social self-esteem","social boldness","sociability","liveliness","agreeableness","forgiveness","gentleness","flexibility","patience","conscientiousness","organization","diligence","perfectionism","prudence","openness to experience","aesthetic appreciation","inquisitiveness","creativity","unconventionality","machiavellianism","narcissism","psychopathy","dominance","anti-egalitarianism","social dominance orientation","pro-market","pro-democracy","ravens","emotionality","extraversion","agreeableness","conscientiousness","openness to experience")
output$exclude<-0
output$exclude[output$measure=="pers.h"]<-1
output$exclude[output$measure=="pers.e"]<-1
output$exclude[output$measure=="pers.x"]<-1
output$exclude[output$measure=="pers.a"]<-1
output$exclude[output$measure=="pers.c"]<-1
output$exclude[output$measure=="pers.o"]<-1
output$exclude[output$measure=="ideology.freemarket"]<-1
output$exclude[output$measure=="ideology.democracy"]<-1
output$exclude[output$measure=="rtotal.correct"]<-1
output$exclude[output$measure=="sdo"]<-1
output$exclude[output$measure=="sdo.antiegalitarianism"]<-1
output$exclude[output$measure=="sdo.dominance"]<-1
output$exclude[output$measure=="sd3.machiavellianism"]<-1
output$exclude[output$measure=="sd3.narcissism"]<-1
output$exclude[output$measure=="sd3.psychopathy"]<-1
output$exclude[output$measure=="tipi.pers.e"]<-1
output$exclude[output$measure=="tipi.pers.x"]<-1
output$exclude[output$measure=="tipi.pers.a"]<-1
output$exclude[output$measure=="tipi.pers.c"]<-1
output$exclude[output$measure=="tipi.pers.o"]<-1
output<-subset(output, output$label!="social dominance orientation")
output.hexaco<-subset(output,output$exclude==0)
output.sum<-subset(output,output$exclude==1)

write.csv(output, "output.cpt.csv")
write.csv(output.hexaco, "output.hexaco.cpt.csv")
write.csv(output.sum, "output.sum.cpt.csv")

pdf('fig-cpt-summary.pdf', width=5.25, height=5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
ggplot(output.sum, aes(x=coeff, y=reorder(label,coeff), color=facet)) + geom_point(size=2, alpha=.7)  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Personality and Other Attributes") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50")  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_segment(aes(y = label, x = l95ci, yend = label, xend = u95ci), alpha=.7, lwd=1, data = output.sum) + facet_grid(facet2 ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575)) + scale_colour_manual(values=c("#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#b3b3b3","#b3b3b3","#b3b3b3","#b3b3b3"))
dev.off()

pdf('fig-cpt-subfacets.pdf', width=7, height=5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
ggplot(output.hexaco, aes(x=coeff, y=reorder(label,coeff), colour=facet)) + geom_point(size=2, alpha=.7)  + xlab("Difference in Means (Discontents - Supporters)") + ylab("HEXACO Subfacets") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50") + scale_x_continuous(limits = c(-.65,.65))  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_segment(aes(y = label, x = l95ci, yend = label, xend = u95ci), alpha=.7, lwd=1, data = output.hexaco) + scale_colour_brewer(palette = "Set2", aesthetics = "colour")
dev.off()

#Figure: Personality and Self-censorship#

m1<-with(a.mids, lm(pers.h~selfcens))
m2<-with(a.mids, lm(pers.h.sincerity~selfcens)) 
m3<-with(a.mids, lm(pers.h.fairness~selfcens))
m4<-with(a.mids, lm(pers.h.greedavoidance~selfcens)) 
m5<-with(a.mids, lm(pers.h.modesty~selfcens))
m6<-with(a.mids, lm(pers.e~selfcens))
m7<-with(a.mids, lm(pers.e.fearfulness~selfcens)) 
m8<-with(a.mids, lm(pers.e.anxiety~selfcens)) 
m9<-with(a.mids, lm(pers.e.dependence~selfcens)) 
m10<-with(a.mids, lm(pers.e.sentimentality~selfcens)) 
m11<-with(a.mids, lm(pers.x~selfcens)) 
m12<-with(a.mids, lm(pers.x.socialselfesteem~selfcens)) 
m13<-with(a.mids, lm(pers.x.socialboldness~selfcens)) 
m14<-with(a.mids, lm(pers.x.sociability~selfcens)) 
m15<-with(a.mids, lm(pers.x.liveliness~selfcens)) 
m16<-with(a.mids, lm(pers.a~selfcens)) 
m17<-with(a.mids, lm(pers.a.forgiveness~selfcens)) 
m18<-with(a.mids, lm(pers.a.gentleness~selfcens)) 
m19<-with(a.mids, lm(pers.a.flexibility~selfcens)) 
m20<-with(a.mids, lm(pers.a.patience~selfcens)) 
m21<-with(a.mids, lm(pers.c~selfcens)) 
m22<-with(a.mids, lm(pers.c.organization~selfcens)) 
m23<-with(a.mids, lm(pers.c.diligence~selfcens)) 
m24<-with(a.mids, lm(pers.c.perfectionism~selfcens)) 
m25<-with(a.mids, lm(pers.c.prudence~selfcens)) 
m26<-with(a.mids, lm(pers.o~selfcens)) 
m27<-with(a.mids, lm(pers.o.aestheticappreciation~selfcens)) 
m28<-with(a.mids, lm(pers.o.inquisitiveness~selfcens)) 
m29<-with(a.mids, lm(pers.o.creativity~selfcens)) 
m30<-with(a.mids, lm(pers.o.unconventionality~selfcens)) 
m31<-with(a.mids, lm(sd3.machiavellianism~selfcens)) 
m32<-with(a.mids, lm(sd3.narcissism~selfcens)) 
m33<-with(a.mids, lm(sd3.psychopathy~selfcens)) 
m34<-with(a.mids, lm(sdo.dominance~selfcens))
m35<-with(a.mids, lm(sdo.antiegalitarianism~selfcens)) 
m36<-with(a.mids, lm(sdo~selfcens)) 
m37<-with(a.mids, lm(ideology.freemarket~selfcens)) 
m38<-with(a.mids, lm(ideology.democracy~selfcens)) 
m39<-with(a.mids, lm(rtotal.correct~selfcens)) 
m40<-with(a.mids, lm(tipi.pers.x~selfcens)) 
m41<-with(a.mids, lm(tipi.pers.a~selfcens)) 
m42<-with(a.mids, lm(tipi.pers.c~selfcens)) 
m43<-with(a.mids, lm(tipi.pers.e~selfcens)) 
m44<-with(a.mids, lm(tipi.pers.o~selfcens))

output <- matrix(data = NA, nrow=44, ncol=5)
output<-data.frame(output)
colnames(output)<-c("measure", "estimate","se")
output$measure<-rep(c("pers.h","pers.h.sincerity","pers.h.fairness","pers.h.greedavoidance","pers.h.modesty","pers.e","pers.e.fearfulness","pers.e.anxiety","pers.e.dependence","pers.e.sentimentality","pers.x","pers.x.socialselfesteem","pers.x.socialboldness","pers.x.sociability","pers.x.liveliness","pers.a","pers.a.forgiveness","pers.a.gentleness","pers.a.flexibility","pers.a.patience","pers.c","pers.c.organization","pers.c.diligence","pers.c.perfectionism","pers.c.prudence","pers.o","pers.o.aestheticappreciation","pers.o.inquisitiveness","pers.o.creativity","pers.o.unconventionality","sd3.machiavellianism","sd3.narcissism","sd3.psychopathy","sdo.dominance","sdo.antiegalitarianism","sdo","ideology.freemarket","ideology.democracy","rtotal.correct","tipi.pers.e","tipi.pers.x","tipi.pers.a","tipi.pers.c","tipi.pers.o"), times=1)
output$label<-rep(c("Honesty-Humility","Honesty-Humility - Sincerity","Honesty-Humility - Fairness","Honesty-Humility - Greed Avoidance","Honesty-Humility - Modesty","Emotionality","Emotionality - Fearfulness","Emotionality - Anxiety","Emotionality - Dependence","Emotionality - Sentimentality","eXtraversion","eXtraversion - Social Self Esteem","eXtraversion - Social Boldness","eXtraversion - Sociability","eXtraversion - Liveliness", "Agreeableness", "Agreeableness - Forgiveness","Agreeableness - Gentleness","Agreeableness - Flexibility","Agreeableness - Patience","Conscientiousness","Conscientiousness - Organization","Conscientiousness - Diligence","Conscientiousness - Perfectionism","Conscientiousness - Prudence","Openness","Openness - Aesthetic Appreciation","Openness - Inquisitiveness","Openness - Creativity","Openness - Unconventionality","Machiavellianism","Narcissism","Psychopathy","Dominance","Antiegalitarianism","Social Dominance Orientation","Economic Liberalism","Political Liberalism","IQ", "Emotionality","eXtraversion","Agreeableness","Conscientiousness","Openness to Experience"), times=1)
output$facet<-rep(c("H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","E. Emotionality","E. Emotionality","E. Emotionality","E. Emotionality","E. Emotionality","X. Extraversion","X. Extraversion","X. Extraversion","X. Extraversion","X. Extraversion","A. Agreeableness","A. Agreeableness","A. Agreeableness","A. Agreeableness","A. Agreeableness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","Dark Triad","Dark Triad","Dark Triad","SDO","SDO","SDO","Ideology","Ideology","IQ","E. Emotionality","X. Extraversion", "A. Agreeableness", "C. Conscientiousness", "O. Openness to Experience"), times=1)
output$facet = factor(output$facet,levels=c("H. Honesty-Humility", "E. Emotionality","X. Extraversion","A. Agreeableness","C. Conscientiousness","O. Openness to Experience","Dark Triad","SDO","IQ","Ideology"))
output$facet2<-rep(c("HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","Dark Triad","Dark Triad","Dark Triad","SDO","SDO","SDO","Ideology","Ideology","IQ","TIPI FFM","TIPI FFM", "TIPI FFM", "TIPI FFM", "TIPI FFM"), times=1)
output$facet2 = factor(output$facet2,levels=c("HEXACO", "TIPI FFM","Dark Triad", "SDO","IQ","Ideology"))

for (j in 1:44) {
  try(eval(parse(text=paste("output$coeff[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,2]",sep=""))))
  try(eval(parse(text=paste("output$se[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,3]",sep=""))))
  }  

output$l95ci<-output$coeff-1.96*output$se
output$u95ci<-output$coeff+1.96*output$se

output$label<-c("honesty-humility","sincerity","fairness","greed avoidance","modesty","emotionality","fearfulness","anxiety","dependence","sentimentality","extraversion","social self-esteem","social boldness","sociability","liveliness","agreeableness","forgiveness","gentleness","flexibility","patience","conscientiousness","organization","diligence","perfectionism","prudence","openness to experience","aesthetic appreciation","inquisitiveness","creativity","unconventionality","machiavellianism","narcissism","psychopathy","dominance","anti-egalitarianism","social dominance orientation","pro-market","pro-democracy","ravens","emotionality","extraversion","agreeableness","conscientiousness","openness to experience")
output$exclude<-0
output$exclude[output$measure=="pers.h"]<-1
output$exclude[output$measure=="pers.e"]<-1
output$exclude[output$measure=="pers.x"]<-1
output$exclude[output$measure=="pers.a"]<-1
output$exclude[output$measure=="pers.c"]<-1
output$exclude[output$measure=="pers.o"]<-1
output$exclude[output$measure=="ideology.freemarket"]<-1
output$exclude[output$measure=="ideology.democracy"]<-1
output$exclude[output$measure=="rtotal.correct"]<-1
output$exclude[output$measure=="sdo"]<-1
output$exclude[output$measure=="sdo.antiegalitarianism"]<-1
output$exclude[output$measure=="sdo.dominance"]<-1
output$exclude[output$measure=="sd3.machiavellianism"]<-1
output$exclude[output$measure=="sd3.narcissism"]<-1
output$exclude[output$measure=="sd3.psychopathy"]<-1
output$exclude[output$measure=="tipi.pers.e"]<-1
output$exclude[output$measure=="tipi.pers.x"]<-1
output$exclude[output$measure=="tipi.pers.a"]<-1
output$exclude[output$measure=="tipi.pers.c"]<-1
output$exclude[output$measure=="tipi.pers.o"]<-1
output<-subset(output, output$label!="social dominance orientation")
output.hexaco<-subset(output,output$exclude==0)
output.sum<-subset(output,output$exclude==1)

write.csv(output, "output.cpt.selfcens.csv")
write.csv(output.hexaco, "output.hexaco.cpt.selfcens.csv")
write.csv(output.sum, "output.sum.cpt.selfcens.csv")

pdf('fig-cpt-summary-selfcens.pdf', width=5.25, height=5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
ggplot(output.sum, aes(x=coeff, y=reorder(label,coeff), color=facet)) + geom_point(size=2, alpha=.7)  + xlab("Difference in Means (Falsifiers - Other)") + ylab("Personality and Other Attributes") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50")  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_segment(aes(y = label, x = l95ci, yend = label, xend = u95ci), alpha=.7, lwd=1, data = output.sum) + facet_grid(facet2 ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575)) + scale_colour_manual(values=c("#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#b3b3b3","#b3b3b3","#b3b3b3","#b3b3b3"))
dev.off()

pdf('fig-cpt-subfacets-selfcens.pdf', width=7, height=5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
ggplot(output.hexaco, aes(x=coeff, y=reorder(label,coeff), colour=facet)) + geom_point(size=2, alpha=.7)  + xlab("Difference in Means (Falsifiers - Other)") + ylab("HEXACO Subfacets") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50") + scale_x_continuous(limits = c(-.65,.65))  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_segment(aes(y = label, x = l95ci, yend = label, xend = u95ci), alpha=.7, lwd=1, data = output.hexaco) + scale_colour_brewer(palette = "Set2", aesthetics = "colour")
dev.off()

#Table: Discriminating Questions between Supporters and Discontents#

for (j in 1:60) {
  try(eval(parse(text=paste("m",j,"<-with(a.mids, lm(H",j,"n~discontent))",sep="")))) 
}  

output <- matrix(data = NA, nrow=60, ncol=5)
output<-data.frame(output)
colnames(output)<-c("measure", "estimate","se")
output$measure<-rep(c("H1n","H2n","H3n","H4n","H5n","H6n","H7n","H8n","H9n","H10n","H11n","H12n","H13n","H14n","H15n","H16n","H17n","H18n","H19n","H20n","H21n","H22n","H23n","H24n","H25n","H26n","H27n","H28n","H29n","H30n","H31n","H32n","H33n","H34n","H35n","H36n","H37n","H38n","H39n","H40n","H41n","H42n","H43n","H44n","H45n","H46n","H47n","H48n","H49n","H50n","H51n","H52n","H53n","H54n","H55n","H56n","H57n","H58n","H59n","H60n"), times=1)

for (j in 1:60) {
  try(eval(parse(text=paste("output$coeff[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,2]",sep=""))))
  try(eval(parse(text=paste("output$se[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,3]",sep=""))))
}  
output$coeff.abs<-abs(output$coeff)
view(output)

write.csv(output, "output.questions.cpt.csv")

#Figure: Personality Profiles

data$discontent<-NA
data$discontent[data$sat.central=="0"]<-1
data$discontent[data$sat.central=="1"]<-1
data$discontent[data$sat.central=="2"]<-1
data$discontent[data$sat.central=="3"]<-1
data$discontent[data$sat.central=="4"]<-1
data$discontent[data$sat.central=="5"]<-0
data$discontent[data$sat.central=="6"]<-0
data$discontent[data$sat.central=="7"]<-0
data$discontent[data$sat.central=="8"]<-0
data$discontent[data$sat.central=="9"]<-0
data$discontent[data$sat.central=="10"]<-0

data.discontent<-subset(data, data$discontent==1)
data.supporter<-subset(data, data$discontent==0)
data.protest<-subset(data, data$part.protest==1)
data.petition<-subset(data, data$part.petition==1)
data.vote<-subset(data, data$part.voted==1)
data.meeting<-subset(data, data$part.meeting==1)
data.ccp<-subset(data, data$ccp==1)
data.selfcens<-subset(data, data$selfcens==1)

output <- matrix(data = NA, nrow=312, ncol=5)
output<-data.frame(output)
colnames(output)<-c("group","measure", "mean","se")
output$group[1:39]<-"Discontent"
output$group[40:78]<-"Supporter"
output$group[79:117]<-"Sample Average"
output$group[118:156]<-"Protestor"
output$group[157:195]<-"Petitioner"
output$group[196:234]<-"Attended Meeting"
output$group[235:273]<-"CCP Member"
output$group[274:312]<-"Falsifier"

output$measure<-rep(c("pers.h","pers.h.sincerity","pers.h.fairness","pers.h.greedavoidance","pers.h.modesty","pers.e","pers.e.fearfulness","pers.e.anxiety","pers.e.dependence","pers.e.sentimentality","pers.x","pers.x.socialselfesteem","pers.x.socialboldness","pers.x.sociability","pers.x.liveliness","pers.a","pers.a.forgiveness","pers.a.gentleness","pers.a.flexibility","pers.a.patience","pers.c","pers.c.organization","pers.c.diligence","pers.c.perfectionism","pers.c.prudence","pers.o","pers.o.aestheticappreciation","pers.o.inquisitiveness","pers.o.creativity","pers.o.unconventionality","sd3.machiavellianism","sd3.narcissism","sd3.psychopathy","sdo.dominance","sdo.antiegalitarianism","sdo","ideology.freemarket","ideology.democracy","rtotal.correct"), times=8)
output$label<-rep(c("Honesty-Humility","Honesty-Humility - Sincerity","Honesty-Humility - Fairness","Honesty-Humility - Greed Avoidance","Honesty-Humility - Modesty","Emotionality","Emotionality - Fearfulness","Emotionality - Anxiety","Emotionality - Dependence","Emotionality - Sentimentality","eXtraversion","eXtraversion - Social Self Esteem","eXtraversion - Social Boldness","eXtraversion - Sociability","eXtraversion - Liveliness", "Agreeableness", "Agreeableness - Forgiveness","Agreeableness - Gentleness","Agreeableness - Flexibility","Agreeableness - Patience","Conscientiousness","Conscientiousness - Organization","Conscientiousness - Diligence","Conscientiousness - Perfectionism","Conscientiousness - Prudence","Openness","Openness - Aesthetic Appreciation","Openness - Inquisitiveness","Openness - Creativity","Openness - Unconventionality","Machiavellianism","Narcissism","Psychopathy","Dominance","Antiegalitarianism","Social Dominance Orientation","Economic Liberalism","Political Liberalism","Intellect"), times=8)
output$facet<-rep(c("HEXACO - H","HEXACO - H","HEXACO - H","HEXACO - H","HEXACO - H","HEXACO - E","HEXACO - E","HEXACO - E","HEXACO - E","HEXACO - E","HEXACO - X","HEXACO - X","HEXACO - X","HEXACO - X","HEXACO - X","HEXACO - A","HEXACO - A","HEXACO - A","HEXACO - A","HEXACO - A","HEXACO - C","HEXACO - C","HEXACO - C","HEXACO - C","HEXACO - C","HEXACO - O","HEXACO - O","HEXACO - O","HEXACO - O","HEXACO - O","Dark Triad","Dark Triad","Dark Triad","SDO","SDO","SDO","Ideology","Ideology","Ravens"), times=8)

output$mean[1]<-mean(data.discontent$pers.h, na.rm=TRUE)
output$mean[2]<-mean(data.discontent$pers.h.sincerity, na.rm=TRUE)
output$mean[3]<-mean(data.discontent$pers.h.fairness, na.rm=TRUE)
output$mean[4]<-mean(data.discontent$pers.h.greedavoidance, na.rm=TRUE)
output$mean[5]<-mean(data.discontent$pers.h.modesty, na.rm=TRUE)
output$mean[6]<-mean(data.discontent$pers.e, na.rm=TRUE)
output$mean[7]<-mean(data.discontent$pers.e.fearfulness, na.rm=TRUE)
output$mean[8]<-mean(data.discontent$pers.e.anxiety, na.rm=TRUE)
output$mean[9]<-mean(data.discontent$pers.e.dependence, na.rm=TRUE)
output$mean[10]<-mean(data.discontent$pers.e.sentimentality, na.rm=TRUE)
output$mean[11]<-mean(data.discontent$pers.x, na.rm=TRUE)
output$mean[12]<-mean(data.discontent$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[13]<-mean(data.discontent$pers.x.socialboldness, na.rm=TRUE)
output$mean[14]<-mean(data.discontent$pers.x.sociability, na.rm=TRUE)
output$mean[15]<-mean(data.discontent$pers.x.liveliness, na.rm=TRUE)
output$mean[16]<-mean(data.discontent$pers.a, na.rm=TRUE)
output$mean[17]<-mean(data.discontent$pers.a.forgiveness, na.rm=TRUE)
output$mean[18]<-mean(data.discontent$pers.a.gentleness, na.rm=TRUE)
output$mean[19]<-mean(data.discontent$pers.a.flexibility, na.rm=TRUE)
output$mean[20]<-mean(data.discontent$pers.a.patience, na.rm=TRUE)
output$mean[21]<-mean(data.discontent$pers.c, na.rm=TRUE)
output$mean[22]<-mean(data.discontent$pers.c.organization, na.rm=TRUE)
output$mean[23]<-mean(data.discontent$pers.c.diligence, na.rm=TRUE)
output$mean[24]<-mean(data.discontent$pers.c.perfectionism, na.rm=TRUE)
output$mean[25]<-mean(data.discontent$pers.c.prudence, na.rm=TRUE)
output$mean[26]<-mean(data.discontent$pers.o, na.rm=TRUE)
output$mean[27]<-mean(data.discontent$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[28]<-mean(data.discontent$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[29]<-mean(data.discontent$pers.o.creativity, na.rm=TRUE)
output$mean[30]<-mean(data.discontent$pers.o.unconventionality, na.rm=TRUE)
output$mean[31]<-mean(data.discontent$sd3.machiavellianism, na.rm=TRUE)
output$mean[32]<-mean(data.discontent$sd3.narcissism, na.rm=TRUE)
output$mean[33]<-mean(data.discontent$sd3.psychopathy, na.rm=TRUE)
output$mean[34]<-mean(data.discontent$sdo.dominance, na.rm=TRUE)
output$mean[35]<-mean(data.discontent$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[36]<-mean(data.discontent$sdo, na.rm=TRUE)
output$mean[37]<-mean(data.discontent$ideology.freemarket, na.rm=TRUE)
output$mean[38]<-mean(data.discontent$ideology.democracy, na.rm=TRUE)
output$mean[39]<-mean(data.discontent$rtotal.correct, na.rm=TRUE)
output$mean[40]<-mean(data.supporter$pers.h, na.rm=TRUE)
output$mean[41]<-mean(data.supporter$pers.h.sincerity, na.rm=TRUE)
output$mean[42]<-mean(data.supporter$pers.h.fairness, na.rm=TRUE)
output$mean[43]<-mean(data.supporter$pers.h.greedavoidance, na.rm=TRUE)
output$mean[44]<-mean(data.supporter$pers.h.modesty, na.rm=TRUE)
output$mean[45]<-mean(data.supporter$pers.e, na.rm=TRUE)
output$mean[46]<-mean(data.supporter$pers.e.fearfulness, na.rm=TRUE)
output$mean[47]<-mean(data.supporter$pers.e.anxiety, na.rm=TRUE)
output$mean[48]<-mean(data.supporter$pers.e.dependence, na.rm=TRUE)
output$mean[49]<-mean(data.supporter$pers.e.sentimentality, na.rm=TRUE)
output$mean[50]<-mean(data.supporter$pers.x, na.rm=TRUE)
output$mean[51]<-mean(data.supporter$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[52]<-mean(data.supporter$pers.x.socialboldness, na.rm=TRUE)
output$mean[53]<-mean(data.supporter$pers.x.sociability, na.rm=TRUE)
output$mean[54]<-mean(data.supporter$pers.x.liveliness, na.rm=TRUE)
output$mean[55]<-mean(data.supporter$pers.a, na.rm=TRUE)
output$mean[56]<-mean(data.supporter$pers.a.forgiveness, na.rm=TRUE)
output$mean[57]<-mean(data.supporter$pers.a.gentleness, na.rm=TRUE)
output$mean[58]<-mean(data.supporter$pers.a.flexibility, na.rm=TRUE)
output$mean[59]<-mean(data.supporter$pers.a.patience, na.rm=TRUE)
output$mean[60]<-mean(data.supporter$pers.c, na.rm=TRUE)
output$mean[61]<-mean(data.supporter$pers.c.organization, na.rm=TRUE)
output$mean[62]<-mean(data.supporter$pers.c.diligence, na.rm=TRUE)
output$mean[63]<-mean(data.supporter$pers.c.perfectionism, na.rm=TRUE)
output$mean[64]<-mean(data.supporter$pers.c.prudence, na.rm=TRUE)
output$mean[65]<-mean(data.supporter$pers.o, na.rm=TRUE)
output$mean[66]<-mean(data.supporter$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[67]<-mean(data.supporter$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[68]<-mean(data.supporter$pers.o.creativity, na.rm=TRUE)
output$mean[69]<-mean(data.supporter$pers.o.unconventionality, na.rm=TRUE)
output$mean[70]<-mean(data.supporter$sd3.machiavellianism, na.rm=TRUE)
output$mean[71]<-mean(data.supporter$sd3.narcissism, na.rm=TRUE)
output$mean[72]<-mean(data.supporter$sd3.psychopathy, na.rm=TRUE)
output$mean[73]<-mean(data.supporter$sdo.dominance, na.rm=TRUE)
output$mean[74]<-mean(data.supporter$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[75]<-mean(data.supporter$sdo, na.rm=TRUE)
output$mean[76]<-mean(data.supporter$ideology.freemarket, na.rm=TRUE)
output$mean[77]<-mean(data.supporter$ideology.democracy, na.rm=TRUE)
output$mean[78]<-mean(data.supporter$rtotal.correct, na.rm=TRUE)
output$mean[79]<-mean(data$pers.h, na.rm=TRUE)
output$mean[80]<-mean(data$pers.h.sincerity, na.rm=TRUE)
output$mean[81]<-mean(data$pers.h.fairness, na.rm=TRUE)
output$mean[82]<-mean(data$pers.h.greedavoidance, na.rm=TRUE)
output$mean[83]<-mean(data$pers.h.modesty, na.rm=TRUE)
output$mean[84]<-mean(data$pers.e, na.rm=TRUE)
output$mean[85]<-mean(data$pers.e.fearfulness, na.rm=TRUE)
output$mean[86]<-mean(data$pers.e.anxiety, na.rm=TRUE)
output$mean[87]<-mean(data$pers.e.dependence, na.rm=TRUE)
output$mean[88]<-mean(data$pers.e.sentimentality, na.rm=TRUE)
output$mean[89]<-mean(data$pers.x, na.rm=TRUE)
output$mean[90]<-mean(data$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[91]<-mean(data$pers.x.socialboldness, na.rm=TRUE)
output$mean[92]<-mean(data$pers.x.sociability, na.rm=TRUE)
output$mean[93]<-mean(data$pers.x.liveliness, na.rm=TRUE)
output$mean[94]<-mean(data$pers.a, na.rm=TRUE)
output$mean[95]<-mean(data$pers.a.forgiveness, na.rm=TRUE)
output$mean[96]<-mean(data$pers.a.gentleness, na.rm=TRUE)
output$mean[97]<-mean(data$pers.a.flexibility, na.rm=TRUE)
output$mean[98]<-mean(data$pers.a.patience, na.rm=TRUE)
output$mean[99]<-mean(data$pers.c, na.rm=TRUE)
output$mean[100]<-mean(data$pers.c.organization, na.rm=TRUE)
output$mean[101]<-mean(data$pers.c.diligence, na.rm=TRUE)
output$mean[102]<-mean(data$pers.c.perfectionism, na.rm=TRUE)
output$mean[103]<-mean(data$pers.c.prudence, na.rm=TRUE)
output$mean[104]<-mean(data$pers.o, na.rm=TRUE)
output$mean[105]<-mean(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[106]<-mean(data$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[107]<-mean(data$pers.o.creativity, na.rm=TRUE)
output$mean[108]<-mean(data$pers.o.unconventionality, na.rm=TRUE)
output$mean[109]<-mean(data$sd3.machiavellianism, na.rm=TRUE)
output$mean[110]<-mean(data$sd3.narcissism, na.rm=TRUE)
output$mean[111]<-mean(data$sd3.psychopathy, na.rm=TRUE)
output$mean[112]<-mean(data$sdo.dominance, na.rm=TRUE)
output$mean[113]<-mean(data$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[114]<-mean(data$sdo, na.rm=TRUE)
output$mean[115]<-mean(data$ideology.freemarket, na.rm=TRUE)
output$mean[116]<-mean(data$ideology.democracy, na.rm=TRUE)
output$mean[117]<-mean(data$rtotal.correct, na.rm=TRUE)
output$mean[118]<-mean(data.protest$pers.h, na.rm=TRUE)
output$mean[119]<-mean(data.protest$pers.h.sincerity, na.rm=TRUE)
output$mean[120]<-mean(data.protest$pers.h.fairness, na.rm=TRUE)
output$mean[121]<-mean(data.protest$pers.h.greedavoidance, na.rm=TRUE)
output$mean[122]<-mean(data.protest$pers.h.modesty, na.rm=TRUE)
output$mean[123]<-mean(data.protest$pers.e, na.rm=TRUE)
output$mean[124]<-mean(data.protest$pers.e.fearfulness, na.rm=TRUE)
output$mean[125]<-mean(data.protest$pers.e.anxiety, na.rm=TRUE)
output$mean[126]<-mean(data.protest$pers.e.dependence, na.rm=TRUE)
output$mean[127]<-mean(data.protest$pers.e.sentimentality, na.rm=TRUE)
output$mean[128]<-mean(data.protest$pers.x, na.rm=TRUE)
output$mean[129]<-mean(data.protest$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[130]<-mean(data.protest$pers.x.socialboldness, na.rm=TRUE)
output$mean[131]<-mean(data.protest$pers.x.sociability, na.rm=TRUE)
output$mean[132]<-mean(data.protest$pers.x.liveliness, na.rm=TRUE)
output$mean[133]<-mean(data.protest$pers.a, na.rm=TRUE)
output$mean[134]<-mean(data.protest$pers.a.forgiveness, na.rm=TRUE)
output$mean[135]<-mean(data.protest$pers.a.gentleness, na.rm=TRUE)
output$mean[136]<-mean(data.protest$pers.a.flexibility, na.rm=TRUE)
output$mean[137]<-mean(data.protest$pers.a.patience, na.rm=TRUE)
output$mean[138]<-mean(data.protest$pers.c, na.rm=TRUE)
output$mean[139]<-mean(data.protest$pers.c.organization, na.rm=TRUE)
output$mean[140]<-mean(data.protest$pers.c.diligence, na.rm=TRUE)
output$mean[141]<-mean(data.protest$pers.c.perfectionism, na.rm=TRUE)
output$mean[142]<-mean(data.protest$pers.c.prudence, na.rm=TRUE)
output$mean[143]<-mean(data.protest$pers.o, na.rm=TRUE)
output$mean[144]<-mean(data.protest$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[145]<-mean(data.protest$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[146]<-mean(data.protest$pers.o.creativity, na.rm=TRUE)
output$mean[147]<-mean(data.protest$pers.o.unconventionality, na.rm=TRUE)
output$mean[148]<-mean(data.protest$sd3.machiavellianism, na.rm=TRUE)
output$mean[149]<-mean(data.protest$sd3.narcissism, na.rm=TRUE)
output$mean[150]<-mean(data.protest$sd3.psychopathy, na.rm=TRUE)
output$mean[151]<-mean(data.protest$sdo.dominance, na.rm=TRUE)
output$mean[152]<-mean(data.protest$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[153]<-mean(data.protest$sdo, na.rm=TRUE)
output$mean[154]<-mean(data.protest$ideology.freemarket, na.rm=TRUE)
output$mean[155]<-mean(data.protest$ideology.democracy, na.rm=TRUE)
output$mean[156]<-mean(data.protest$rtotal.correct, na.rm=TRUE)
output$mean[157]<-mean(data.petition$pers.h, na.rm=TRUE)
output$mean[158]<-mean(data.petition$pers.h.sincerity, na.rm=TRUE)
output$mean[159]<-mean(data.petition$pers.h.fairness, na.rm=TRUE)
output$mean[160]<-mean(data.petition$pers.h.greedavoidance, na.rm=TRUE)
output$mean[161]<-mean(data.petition$pers.h.modesty, na.rm=TRUE)
output$mean[162]<-mean(data.petition$pers.e, na.rm=TRUE)
output$mean[163]<-mean(data.petition$pers.e.fearfulness, na.rm=TRUE)
output$mean[164]<-mean(data.petition$pers.e.anxiety, na.rm=TRUE)
output$mean[165]<-mean(data.petition$pers.e.dependence, na.rm=TRUE)
output$mean[166]<-mean(data.petition$pers.e.sentimentality, na.rm=TRUE)
output$mean[167]<-mean(data.petition$pers.x, na.rm=TRUE)
output$mean[168]<-mean(data.petition$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[169]<-mean(data.petition$pers.x.socialboldness, na.rm=TRUE)
output$mean[170]<-mean(data.petition$pers.x.sociability, na.rm=TRUE)
output$mean[171]<-mean(data.petition$pers.x.liveliness, na.rm=TRUE)
output$mean[172]<-mean(data.petition$pers.a, na.rm=TRUE)
output$mean[173]<-mean(data.petition$pers.a.forgiveness, na.rm=TRUE)
output$mean[174]<-mean(data.petition$pers.a.gentleness, na.rm=TRUE)
output$mean[175]<-mean(data.petition$pers.a.flexibility, na.rm=TRUE)
output$mean[176]<-mean(data.petition$pers.a.patience, na.rm=TRUE)
output$mean[177]<-mean(data.petition$pers.c, na.rm=TRUE)
output$mean[178]<-mean(data.petition$pers.c.organization, na.rm=TRUE)
output$mean[179]<-mean(data.petition$pers.c.diligence, na.rm=TRUE)
output$mean[180]<-mean(data.petition$pers.c.perfectionism, na.rm=TRUE)
output$mean[181]<-mean(data.petition$pers.c.prudence, na.rm=TRUE)
output$mean[182]<-mean(data.petition$pers.o, na.rm=TRUE)
output$mean[183]<-mean(data.petition$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[184]<-mean(data.petition$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[185]<-mean(data.petition$pers.o.creativity, na.rm=TRUE)
output$mean[186]<-mean(data.petition$pers.o.unconventionality, na.rm=TRUE)
output$mean[187]<-mean(data.petition$sd3.machiavellianism, na.rm=TRUE)
output$mean[188]<-mean(data.petition$sd3.narcissism, na.rm=TRUE)
output$mean[189]<-mean(data.petition$sd3.psychopathy, na.rm=TRUE)
output$mean[190]<-mean(data.petition$sdo.dominance, na.rm=TRUE)
output$mean[191]<-mean(data.petition$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[192]<-mean(data.petition$sdo, na.rm=TRUE)
output$mean[193]<-mean(data.petition$ideology.freemarket, na.rm=TRUE)
output$mean[194]<-mean(data.petition$ideology.democracy, na.rm=TRUE)
output$mean[195]<-mean(data.petition$rtotal.correct, na.rm=TRUE)
output$mean[196]<-mean(data.meeting$pers.h, na.rm=TRUE)
output$mean[197]<-mean(data.meeting$pers.h.sincerity, na.rm=TRUE)
output$mean[198]<-mean(data.meeting$pers.h.fairness, na.rm=TRUE)
output$mean[199]<-mean(data.meeting$pers.h.greedavoidance, na.rm=TRUE)
output$mean[200]<-mean(data.meeting$pers.h.modesty, na.rm=TRUE)
output$mean[201]<-mean(data.meeting$pers.e, na.rm=TRUE)
output$mean[202]<-mean(data.meeting$pers.e.fearfulness, na.rm=TRUE)
output$mean[203]<-mean(data.meeting$pers.e.anxiety, na.rm=TRUE)
output$mean[204]<-mean(data.meeting$pers.e.dependence, na.rm=TRUE)
output$mean[205]<-mean(data.meeting$pers.e.sentimentality, na.rm=TRUE)
output$mean[206]<-mean(data.meeting$pers.x, na.rm=TRUE)
output$mean[207]<-mean(data.meeting$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[208]<-mean(data.meeting$pers.x.socialboldness, na.rm=TRUE)
output$mean[209]<-mean(data.meeting$pers.x.sociability, na.rm=TRUE)
output$mean[210]<-mean(data.meeting$pers.x.liveliness, na.rm=TRUE)
output$mean[211]<-mean(data.meeting$pers.a, na.rm=TRUE)
output$mean[212]<-mean(data.meeting$pers.a.forgiveness, na.rm=TRUE)
output$mean[213]<-mean(data.meeting$pers.a.gentleness, na.rm=TRUE)
output$mean[214]<-mean(data.meeting$pers.a.flexibility, na.rm=TRUE)
output$mean[215]<-mean(data.meeting$pers.a.patience, na.rm=TRUE)
output$mean[216]<-mean(data.meeting$pers.c, na.rm=TRUE)
output$mean[217]<-mean(data.meeting$pers.c.organization, na.rm=TRUE)
output$mean[218]<-mean(data.meeting$pers.c.diligence, na.rm=TRUE)
output$mean[219]<-mean(data.meeting$pers.c.perfectionism, na.rm=TRUE)
output$mean[220]<-mean(data.meeting$pers.c.prudence, na.rm=TRUE)
output$mean[221]<-mean(data.meeting$pers.o, na.rm=TRUE)
output$mean[222]<-mean(data.meeting$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[223]<-mean(data.meeting$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[224]<-mean(data.meeting$pers.o.creativity, na.rm=TRUE)
output$mean[225]<-mean(data.meeting$pers.o.unconventionality, na.rm=TRUE)
output$mean[226]<-mean(data.meeting$sd3.machiavellianism, na.rm=TRUE)
output$mean[227]<-mean(data.meeting$sd3.narcissism, na.rm=TRUE)
output$mean[228]<-mean(data.meeting$sd3.psychopathy, na.rm=TRUE)
output$mean[229]<-mean(data.meeting$sdo.dominance, na.rm=TRUE)
output$mean[230]<-mean(data.meeting$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[231]<-mean(data.meeting$sdo, na.rm=TRUE)
output$mean[232]<-mean(data.meeting$ideology.freemarket, na.rm=TRUE)
output$mean[233]<-mean(data.meeting$ideology.democracy, na.rm=TRUE)
output$mean[234]<-mean(data.meeting$rtotal.correct, na.rm=TRUE)
output$mean[235]<-mean(data.ccp$pers.h, na.rm=TRUE)
output$mean[236]<-mean(data.ccp$pers.h.sincerity, na.rm=TRUE)
output$mean[237]<-mean(data.ccp$pers.h.fairness, na.rm=TRUE)
output$mean[238]<-mean(data.ccp$pers.h.greedavoidance, na.rm=TRUE)
output$mean[239]<-mean(data.ccp$pers.h.modesty, na.rm=TRUE)
output$mean[240]<-mean(data.ccp$pers.e, na.rm=TRUE)
output$mean[241]<-mean(data.ccp$pers.e.fearfulness, na.rm=TRUE)
output$mean[242]<-mean(data.ccp$pers.e.anxiety, na.rm=TRUE)
output$mean[243]<-mean(data.ccp$pers.e.dependence, na.rm=TRUE)
output$mean[244]<-mean(data.ccp$pers.e.sentimentality, na.rm=TRUE)
output$mean[245]<-mean(data.ccp$pers.x, na.rm=TRUE)
output$mean[246]<-mean(data.ccp$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[247]<-mean(data.ccp$pers.x.socialboldness, na.rm=TRUE)
output$mean[248]<-mean(data.ccp$pers.x.sociability, na.rm=TRUE)
output$mean[249]<-mean(data.ccp$pers.x.liveliness, na.rm=TRUE)
output$mean[250]<-mean(data.ccp$pers.a, na.rm=TRUE)
output$mean[251]<-mean(data.ccp$pers.a.forgiveness, na.rm=TRUE)
output$mean[252]<-mean(data.ccp$pers.a.gentleness, na.rm=TRUE)
output$mean[253]<-mean(data.ccp$pers.a.flexibility, na.rm=TRUE)
output$mean[254]<-mean(data.ccp$pers.a.patience, na.rm=TRUE)
output$mean[255]<-mean(data.ccp$pers.c, na.rm=TRUE)
output$mean[256]<-mean(data.ccp$pers.c.organization, na.rm=TRUE)
output$mean[257]<-mean(data.ccp$pers.c.diligence, na.rm=TRUE)
output$mean[258]<-mean(data.ccp$pers.c.perfectionism, na.rm=TRUE)
output$mean[259]<-mean(data.ccp$pers.c.prudence, na.rm=TRUE)
output$mean[260]<-mean(data.ccp$pers.o, na.rm=TRUE)
output$mean[261]<-mean(data.ccp$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[262]<-mean(data.ccp$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[263]<-mean(data.ccp$pers.o.creativity, na.rm=TRUE)
output$mean[264]<-mean(data.ccp$pers.o.unconventionality, na.rm=TRUE)
output$mean[265]<-mean(data.ccp$sd3.machiavellianism, na.rm=TRUE)
output$mean[266]<-mean(data.ccp$sd3.narcissism, na.rm=TRUE)
output$mean[267]<-mean(data.ccp$sd3.psychopathy, na.rm=TRUE)
output$mean[268]<-mean(data.ccp$sdo.dominance, na.rm=TRUE)
output$mean[269]<-mean(data.ccp$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[270]<-mean(data.ccp$sdo, na.rm=TRUE)
output$mean[271]<-mean(data.ccp$ideology.freemarket, na.rm=TRUE)
output$mean[272]<-mean(data.ccp$ideology.democracy, na.rm=TRUE)
output$mean[273]<-mean(data.ccp$rtotal.correct, na.rm=TRUE)
output$mean[274]<-mean(data.selfcens$pers.h, na.rm=TRUE)
output$mean[275]<-mean(data.selfcens$pers.h.sincerity, na.rm=TRUE)
output$mean[276]<-mean(data.selfcens$pers.h.fairness, na.rm=TRUE)
output$mean[277]<-mean(data.selfcens$pers.h.greedavoidance, na.rm=TRUE)
output$mean[278]<-mean(data.selfcens$pers.h.modesty, na.rm=TRUE)
output$mean[279]<-mean(data.selfcens$pers.e, na.rm=TRUE)
output$mean[280]<-mean(data.selfcens$pers.e.fearfulness, na.rm=TRUE)
output$mean[281]<-mean(data.selfcens$pers.e.anxiety, na.rm=TRUE)
output$mean[282]<-mean(data.selfcens$pers.e.dependence, na.rm=TRUE)
output$mean[283]<-mean(data.selfcens$pers.e.sentimentality, na.rm=TRUE)
output$mean[284]<-mean(data.selfcens$pers.x, na.rm=TRUE)
output$mean[285]<-mean(data.selfcens$pers.x.socialselfesteem, na.rm=TRUE)
output$mean[286]<-mean(data.selfcens$pers.x.socialboldness, na.rm=TRUE)
output$mean[287]<-mean(data.selfcens$pers.x.sociability, na.rm=TRUE)
output$mean[288]<-mean(data.selfcens$pers.x.liveliness, na.rm=TRUE)
output$mean[289]<-mean(data.selfcens$pers.a, na.rm=TRUE)
output$mean[290]<-mean(data.selfcens$pers.a.forgiveness, na.rm=TRUE)
output$mean[291]<-mean(data.selfcens$pers.a.gentleness, na.rm=TRUE)
output$mean[292]<-mean(data.selfcens$pers.a.flexibility, na.rm=TRUE)
output$mean[293]<-mean(data.selfcens$pers.a.patience, na.rm=TRUE)
output$mean[294]<-mean(data.selfcens$pers.c, na.rm=TRUE)
output$mean[295]<-mean(data.selfcens$pers.c.organization, na.rm=TRUE)
output$mean[296]<-mean(data.selfcens$pers.c.diligence, na.rm=TRUE)
output$mean[297]<-mean(data.selfcens$pers.c.perfectionism, na.rm=TRUE)
output$mean[298]<-mean(data.selfcens$pers.c.prudence, na.rm=TRUE)
output$mean[299]<-mean(data.selfcens$pers.o, na.rm=TRUE)
output$mean[300]<-mean(data.selfcens$pers.o.aestheticappreciation, na.rm=TRUE)
output$mean[301]<-mean(data.selfcens$pers.o.inquisitiveness, na.rm=TRUE)
output$mean[302]<-mean(data.selfcens$pers.o.creativity, na.rm=TRUE)
output$mean[303]<-mean(data.selfcens$pers.o.unconventionality, na.rm=TRUE)
output$mean[304]<-mean(data.selfcens$sd3.machiavellianism, na.rm=TRUE)
output$mean[305]<-mean(data.selfcens$sd3.narcissism, na.rm=TRUE)
output$mean[306]<-mean(data.selfcens$sd3.psychopathy, na.rm=TRUE)
output$mean[307]<-mean(data.selfcens$sdo.dominance, na.rm=TRUE)
output$mean[308]<-mean(data.selfcens$sdo.antiegalitarianism, na.rm=TRUE)
output$mean[309]<-mean(data.selfcens$sdo, na.rm=TRUE)
output$mean[310]<-mean(data.selfcens$ideology.freemarket, na.rm=TRUE)
output$mean[311]<-mean(data.selfcens$ideology.democracy, na.rm=TRUE)
output$mean[312]<-mean(data.selfcens$rtotal.correct, na.rm=TRUE)

output$se[1]<-sd(data.discontent$pers.h, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[2]<-sd(data.discontent$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[3]<-sd(data.discontent$pers.h.fairness, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[4]<-sd(data.discontent$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[5]<-sd(data.discontent$pers.h.modesty, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[6]<-sd(data.discontent$pers.e, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[7]<-sd(data.discontent$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[8]<-sd(data.discontent$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[9]<-sd(data.discontent$pers.e.dependence, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[10]<-sd(data.discontent$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[11]<-sd(data.discontent$pers.x, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[12]<-sd(data.discontent$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[13]<-sd(data.discontent$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[14]<-sd(data.discontent$pers.x.sociability, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[15]<-sd(data.discontent$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[16]<-sd(data.discontent$pers.a, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[17]<-sd(data.discontent$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[18]<-sd(data.discontent$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[19]<-sd(data.discontent$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[20]<-sd(data.discontent$pers.a.patience, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[21]<-sd(data.discontent$pers.c, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[22]<-sd(data.discontent$pers.c.organization, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[23]<-sd(data.discontent$pers.c.diligence, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[24]<-sd(data.discontent$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[25]<-sd(data.discontent$pers.c.prudence, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[26]<-sd(data.discontent$pers.o, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[27]<-sd(data.discontent$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[28]<-sd(data.discontent$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[29]<-sd(data.discontent$pers.o.creativity, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[30]<-sd(data.discontent$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[31]<-sd(data.discontent$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[32]<-sd(data.discontent$sd3.narcissism, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[33]<-sd(data.discontent$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[34]<-sd(data.discontent$sdo.dominance, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[35]<-sd(data.discontent$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[36]<-sd(data.discontent$sdo, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[37]<-sd(data.discontent$ideology.freemarket, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[38]<-sd(data.discontent$ideology.democracy, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[39]<-sd(data.discontent$rtotal.correct, na.rm=TRUE)/sqrt(length(data.discontent))
output$se[40]<-sd(data.supporter$pers.h, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[41]<-sd(data.supporter$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[42]<-sd(data.supporter$pers.h.fairness, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[43]<-sd(data.supporter$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[44]<-sd(data.supporter$pers.h.modesty, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[45]<-sd(data.supporter$pers.e, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[46]<-sd(data.supporter$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[47]<-sd(data.supporter$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[48]<-sd(data.supporter$pers.e.dependence, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[49]<-sd(data.supporter$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[50]<-sd(data.supporter$pers.x, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[51]<-sd(data.supporter$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[52]<-sd(data.supporter$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[53]<-sd(data.supporter$pers.x.sociability, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[54]<-sd(data.supporter$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[55]<-sd(data.supporter$pers.a, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[56]<-sd(data.supporter$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[57]<-sd(data.supporter$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[58]<-sd(data.supporter$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[59]<-sd(data.supporter$pers.a.patience, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[60]<-sd(data.supporter$pers.c, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[61]<-sd(data.supporter$pers.c.organization, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[62]<-sd(data.supporter$pers.c.diligence, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[63]<-sd(data.supporter$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[64]<-sd(data.supporter$pers.c.prudence, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[65]<-sd(data.supporter$pers.o, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[66]<-sd(data.supporter$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[67]<-sd(data.supporter$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[68]<-sd(data.supporter$pers.o.creativity, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[69]<-sd(data.supporter$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[70]<-sd(data.supporter$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[71]<-sd(data.supporter$sd3.narcissism, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[72]<-sd(data.supporter$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[73]<-sd(data.supporter$sdo.dominance, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[74]<-sd(data.supporter$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[75]<-sd(data.supporter$sdo, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[76]<-sd(data.supporter$ideology.freemarket, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[77]<-sd(data.supporter$ideology.democracy, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[78]<-sd(data.supporter$rtotal.correct, na.rm=TRUE)/sqrt(length(data.supporter))
output$se[79]<-sd(data$pers.h, na.rm=TRUE)/sqrt(length(data))
output$se[80]<-sd(data$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data))
output$se[81]<-sd(data$pers.h.fairness, na.rm=TRUE)/sqrt(length(data))
output$se[82]<-sd(data$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data))
output$se[83]<-sd(data$pers.h.modesty, na.rm=TRUE)/sqrt(length(data))
output$se[84]<-sd(data$pers.e, na.rm=TRUE)/sqrt(length(data))
output$se[85]<-sd(data$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data))
output$se[86]<-sd(data$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data))
output$se[87]<-sd(data$pers.e.dependence, na.rm=TRUE)/sqrt(length(data))
output$se[88]<-sd(data$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data))
output$se[89]<-sd(data$pers.x, na.rm=TRUE)/sqrt(length(data))
output$se[90]<-sd(data$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data))
output$se[91]<-sd(data$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data))
output$se[92]<-sd(data$pers.x.sociability, na.rm=TRUE)/sqrt(length(data))
output$se[93]<-sd(data$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data))
output$se[94]<-sd(data$pers.a, na.rm=TRUE)/sqrt(length(data))
output$se[95]<-sd(data$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data))
output$se[96]<-sd(data$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data))
output$se[97]<-sd(data$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data))
output$se[98]<-sd(data$pers.a.patience, na.rm=TRUE)/sqrt(length(data))
output$se[99]<-sd(data$pers.c, na.rm=TRUE)/sqrt(length(data))
output$se[100]<-sd(data$pers.c.organization, na.rm=TRUE)/sqrt(length(data))
output$se[101]<-sd(data$pers.c.diligence, na.rm=TRUE)/sqrt(length(data))
output$se[102]<-sd(data$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data))
output$se[103]<-sd(data$pers.c.prudence, na.rm=TRUE)/sqrt(length(data))
output$se[104]<-sd(data$pers.o, na.rm=TRUE)/sqrt(length(data))
output$se[105]<-sd(data$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data))
output$se[106]<-sd(data$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data))
output$se[107]<-sd(data$pers.o.creativity, na.rm=TRUE)/sqrt(length(data))
output$se[108]<-sd(data$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data))
output$se[109]<-sd(data$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data))
output$se[110]<-sd(data$sd3.narcissism, na.rm=TRUE)/sqrt(length(data))
output$se[111]<-sd(data$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data))
output$se[112]<-sd(data$sdo.dominance, na.rm=TRUE)/sqrt(length(data))
output$se[113]<-sd(data$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data))
output$se[114]<-sd(data$sdo, na.rm=TRUE)/sqrt(length(data))
output$se[115]<-sd(data$ideology.freemarket, na.rm=TRUE)/sqrt(length(data))
output$se[116]<-sd(data$ideology.democracy, na.rm=TRUE)/sqrt(length(data))
output$se[117]<-sd(data$rtotal.correct, na.rm=TRUE)/sqrt(length(data))
output$se[118]<-sd(data.protest$pers.h, na.rm=TRUE)/sqrt(length(data.protest))
output$se[119]<-sd(data.protest$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data.protest))
output$se[120]<-sd(data.protest$pers.h.fairness, na.rm=TRUE)/sqrt(length(data.protest))
output$se[121]<-sd(data.protest$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data.protest))
output$se[122]<-sd(data.protest$pers.h.modesty, na.rm=TRUE)/sqrt(length(data.protest))
output$se[123]<-sd(data.protest$pers.e, na.rm=TRUE)/sqrt(length(data.protest))
output$se[124]<-sd(data.protest$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data.protest))
output$se[125]<-sd(data.protest$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data.protest))
output$se[126]<-sd(data.protest$pers.e.dependence, na.rm=TRUE)/sqrt(length(data.protest))
output$se[127]<-sd(data.protest$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data.protest))
output$se[128]<-sd(data.protest$pers.x, na.rm=TRUE)/sqrt(length(data.protest))
output$se[129]<-sd(data.protest$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data.protest))
output$se[130]<-sd(data.protest$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data.protest))
output$se[131]<-sd(data.protest$pers.x.sociability, na.rm=TRUE)/sqrt(length(data.protest))
output$se[132]<-sd(data.protest$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data.protest))
output$se[133]<-sd(data.protest$pers.a, na.rm=TRUE)/sqrt(length(data.protest))
output$se[134]<-sd(data.protest$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data.protest))
output$se[135]<-sd(data.protest$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data.protest))
output$se[136]<-sd(data.protest$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data.protest))
output$se[137]<-sd(data.protest$pers.a.patience, na.rm=TRUE)/sqrt(length(data.protest))
output$se[138]<-sd(data.protest$pers.c, na.rm=TRUE)/sqrt(length(data.protest))
output$se[139]<-sd(data.protest$pers.c.organization, na.rm=TRUE)/sqrt(length(data.protest))
output$se[140]<-sd(data.protest$pers.c.diligence, na.rm=TRUE)/sqrt(length(data.protest))
output$se[141]<-sd(data.protest$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data.protest))
output$se[142]<-sd(data.protest$pers.c.prudence, na.rm=TRUE)/sqrt(length(data.protest))
output$se[143]<-sd(data.protest$pers.o, na.rm=TRUE)/sqrt(length(data.protest))
output$se[144]<-sd(data.protest$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data.protest))
output$se[145]<-sd(data.protest$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data.protest))
output$se[146]<-sd(data.protest$pers.o.creativity, na.rm=TRUE)/sqrt(length(data.protest))
output$se[147]<-sd(data.protest$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data.protest))
output$se[148]<-sd(data.protest$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data.protest))
output$se[149]<-sd(data.protest$sd3.narcissism, na.rm=TRUE)/sqrt(length(data.protest))
output$se[150]<-sd(data.protest$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data.protest))
output$se[151]<-sd(data.protest$sdo.dominance, na.rm=TRUE)/sqrt(length(data.protest))
output$se[152]<-sd(data.protest$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data.protest))
output$se[153]<-sd(data.protest$sdo, na.rm=TRUE)/sqrt(length(data.protest))
output$se[154]<-sd(data.protest$ideology.freemarket, na.rm=TRUE)/sqrt(length(data.protest))
output$se[155]<-sd(data.protest$ideology.democracy, na.rm=TRUE)/sqrt(length(data.protest))
output$se[156]<-sd(data.protest$rtotal.correct, na.rm=TRUE)/sqrt(length(data.protest))
output$se[157]<-sd(data.petition$pers.h, na.rm=TRUE)/sqrt(length(data.petition))
output$se[158]<-sd(data.petition$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data.petition))
output$se[159]<-sd(data.petition$pers.h.fairness, na.rm=TRUE)/sqrt(length(data.petition))
output$se[160]<-sd(data.petition$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data.petition))
output$se[161]<-sd(data.petition$pers.h.modesty, na.rm=TRUE)/sqrt(length(data.petition))
output$se[162]<-sd(data.petition$pers.e, na.rm=TRUE)/sqrt(length(data.petition))
output$se[163]<-sd(data.petition$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data.petition))
output$se[164]<-sd(data.petition$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data.petition))
output$se[165]<-sd(data.petition$pers.e.dependence, na.rm=TRUE)/sqrt(length(data.petition))
output$se[166]<-sd(data.petition$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data.petition))
output$se[167]<-sd(data.petition$pers.x, na.rm=TRUE)/sqrt(length(data.petition))
output$se[168]<-sd(data.petition$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data.petition))
output$se[169]<-sd(data.petition$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data.petition))
output$se[170]<-sd(data.petition$pers.x.sociability, na.rm=TRUE)/sqrt(length(data.petition))
output$se[171]<-sd(data.petition$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data.petition))
output$se[172]<-sd(data.petition$pers.a, na.rm=TRUE)/sqrt(length(data.petition))
output$se[173]<-sd(data.petition$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data.petition))
output$se[174]<-sd(data.petition$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data.petition))
output$se[175]<-sd(data.petition$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data.petition))
output$se[176]<-sd(data.petition$pers.a.patience, na.rm=TRUE)/sqrt(length(data.petition))
output$se[177]<-sd(data.petition$pers.c, na.rm=TRUE)/sqrt(length(data.petition))
output$se[178]<-sd(data.petition$pers.c.organization, na.rm=TRUE)/sqrt(length(data.petition))
output$se[179]<-sd(data.petition$pers.c.diligence, na.rm=TRUE)/sqrt(length(data.petition))
output$se[180]<-sd(data.petition$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data.petition))
output$se[181]<-sd(data.petition$pers.c.prudence, na.rm=TRUE)/sqrt(length(data.petition))
output$se[182]<-sd(data.petition$pers.o, na.rm=TRUE)/sqrt(length(data.petition))
output$se[183]<-sd(data.petition$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data.petition))
output$se[184]<-sd(data.petition$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data.petition))
output$se[185]<-sd(data.petition$pers.o.creativity, na.rm=TRUE)/sqrt(length(data.petition))
output$se[186]<-sd(data.petition$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data.petition))
output$se[187]<-sd(data.petition$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data.petition))
output$se[188]<-sd(data.petition$sd3.narcissism, na.rm=TRUE)/sqrt(length(data.petition))
output$se[189]<-sd(data.petition$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data.petition))
output$se[190]<-sd(data.petition$sdo.dominance, na.rm=TRUE)/sqrt(length(data.petition))
output$se[191]<-sd(data.petition$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data.petition))
output$se[192]<-sd(data.petition$sdo, na.rm=TRUE)/sqrt(length(data.petition))
output$se[193]<-sd(data.petition$ideology.freemarket, na.rm=TRUE)/sqrt(length(data.petition))
output$se[194]<-sd(data.petition$ideology.democracy, na.rm=TRUE)/sqrt(length(data.petition))
output$se[195]<-sd(data.petition$rtotal.correct, na.rm=TRUE)/sqrt(length(data.petition))
output$se[196]<-sd(data.meeting$pers.h, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[197]<-sd(data.meeting$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[198]<-sd(data.meeting$pers.h.fairness, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[199]<-sd(data.meeting$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[200]<-sd(data.meeting$pers.h.modesty, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[201]<-sd(data.meeting$pers.e, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[202]<-sd(data.meeting$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[203]<-sd(data.meeting$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[204]<-sd(data.meeting$pers.e.dependence, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[205]<-sd(data.meeting$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[206]<-sd(data.meeting$pers.x, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[207]<-sd(data.meeting$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[208]<-sd(data.meeting$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[209]<-sd(data.meeting$pers.x.sociability, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[210]<-sd(data.meeting$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[211]<-sd(data.meeting$pers.a, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[212]<-sd(data.meeting$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[213]<-sd(data.meeting$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[214]<-sd(data.meeting$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[215]<-sd(data.meeting$pers.a.patience, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[216]<-sd(data.meeting$pers.c, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[217]<-sd(data.meeting$pers.c.organization, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[218]<-sd(data.meeting$pers.c.diligence, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[219]<-sd(data.meeting$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[220]<-sd(data.meeting$pers.c.prudence, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[221]<-sd(data.meeting$pers.o, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[222]<-sd(data.meeting$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[223]<-sd(data.meeting$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[224]<-sd(data.meeting$pers.o.creativity, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[225]<-sd(data.meeting$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[226]<-sd(data.meeting$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[227]<-sd(data.meeting$sd3.narcissism, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[228]<-sd(data.meeting$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[229]<-sd(data.meeting$sdo.dominance, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[230]<-sd(data.meeting$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[231]<-sd(data.meeting$sdo, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[232]<-sd(data.meeting$ideology.freemarket, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[233]<-sd(data.meeting$ideology.democracy, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[234]<-sd(data.meeting$rtotal.correct, na.rm=TRUE)/sqrt(length(data.meeting))
output$se[235]<-sd(data.ccp$pers.h, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[236]<-sd(data.ccp$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[237]<-sd(data.ccp$pers.h.fairness, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[238]<-sd(data.ccp$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[239]<-sd(data.ccp$pers.h.modesty, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[240]<-sd(data.ccp$pers.e, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[241]<-sd(data.ccp$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[242]<-sd(data.ccp$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[243]<-sd(data.ccp$pers.e.dependence, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[244]<-sd(data.ccp$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[245]<-sd(data.ccp$pers.x, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[246]<-sd(data.ccp$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[247]<-sd(data.ccp$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[248]<-sd(data.ccp$pers.x.sociability, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[249]<-sd(data.ccp$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[250]<-sd(data.ccp$pers.a, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[251]<-sd(data.ccp$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[252]<-sd(data.ccp$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[253]<-sd(data.ccp$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[254]<-sd(data.ccp$pers.a.patience, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[255]<-sd(data.ccp$pers.c, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[256]<-sd(data.ccp$pers.c.organization, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[257]<-sd(data.ccp$pers.c.diligence, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[258]<-sd(data.ccp$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[259]<-sd(data.ccp$pers.c.prudence, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[260]<-sd(data.ccp$pers.o, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[261]<-sd(data.ccp$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[262]<-sd(data.ccp$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[263]<-sd(data.ccp$pers.o.creativity, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[264]<-sd(data.ccp$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[265]<-sd(data.ccp$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[266]<-sd(data.ccp$sd3.narcissism, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[267]<-sd(data.ccp$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[268]<-sd(data.ccp$sdo.dominance, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[269]<-sd(data.ccp$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[270]<-sd(data.ccp$sdo, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[271]<-sd(data.ccp$ideology.freemarket, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[272]<-sd(data.ccp$ideology.democracy, na.rm=TRUE)/sqrt(length(data.ccp))
output$se[273]<-sd(data.ccp$rtotal.correct, na.rm=TRUE)/sqrt(length(data.ccp))

output$se[274]<-sd(data.selfcens$pers.h, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[275]<-sd(data.selfcens$pers.h.sincerity, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[276]<-sd(data.selfcens$pers.h.fairness, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[277]<-sd(data.selfcens$pers.h.greedavoidance, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[278]<-sd(data.selfcens$pers.h.modesty, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[279]<-sd(data.selfcens$pers.e, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[280]<-sd(data.selfcens$pers.e.fearfulness, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[281]<-sd(data.selfcens$pers.e.anxiety, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[282]<-sd(data.selfcens$pers.e.dependence, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[283]<-sd(data.selfcens$pers.e.sentimentality, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[284]<-sd(data.selfcens$pers.x, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[285]<-sd(data.selfcens$pers.x.socialselfesteem, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[286]<-sd(data.selfcens$pers.x.socialboldness, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[287]<-sd(data.selfcens$pers.x.sociability, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[288]<-sd(data.selfcens$pers.x.liveliness, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[289]<-sd(data.selfcens$pers.a, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[290]<-sd(data.selfcens$pers.a.forgiveness, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[291]<-sd(data.selfcens$pers.a.gentleness, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[292]<-sd(data.selfcens$pers.a.flexibility, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[293]<-sd(data.selfcens$pers.a.patience, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[294]<-sd(data.selfcens$pers.c, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[295]<-sd(data.selfcens$pers.c.organization, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[296]<-sd(data.selfcens$pers.c.diligence, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[297]<-sd(data.selfcens$pers.c.perfectionism, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[298]<-sd(data.selfcens$pers.c.prudence, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[299]<-sd(data.selfcens$pers.o, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[300]<-sd(data.selfcens$pers.o.aestheticappreciation, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[301]<-sd(data.selfcens$pers.o.inquisitiveness, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[302]<-sd(data.selfcens$pers.o.creativity, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[303]<-sd(data.selfcens$pers.o.unconventionality, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[304]<-sd(data.selfcens$sd3.machiavellianism, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[305]<-sd(data.selfcens$sd3.narcissism, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[306]<-sd(data.selfcens$sd3.psychopathy, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[307]<-sd(data.selfcens$sdo.dominance, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[308]<-sd(data.selfcens$sdo.antiegalitarianism, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[309]<-sd(data.selfcens$sdo, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[310]<-sd(data.selfcens$ideology.freemarket, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[311]<-sd(data.selfcens$ideology.democracy, na.rm=TRUE)/sqrt(length(data.selfcens))
output$se[312]<-sd(data.selfcens$rtotal.correct, na.rm=TRUE)/sqrt(length(data.selfcens))

output$stdmean[1]<-(mean(data.discontent$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[2]<-(mean(data.discontent$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[3]<-(mean(data.discontent$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[4]<-(mean(data.discontent$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[5]<-(mean(data.discontent$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[6]<-(mean(data.discontent$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[7]<-(mean(data.discontent$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[8]<-(mean(data.discontent$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[9]<-(mean(data.discontent$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[10]<-(mean(data.discontent$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[11]<-(mean(data.discontent$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[12]<-(mean(data.discontent$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[13]<-(mean(data.discontent$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[14]<-(mean(data.discontent$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[15]<-(mean(data.discontent$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[16]<-(mean(data.discontent$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[17]<-(mean(data.discontent$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[18]<-(mean(data.discontent$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[19]<-(mean(data.discontent$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[20]<-(mean(data.discontent$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[21]<-(mean(data.discontent$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[22]<-(mean(data.discontent$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[23]<-(mean(data.discontent$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[24]<-(mean(data.discontent$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[25]<-(mean(data.discontent$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[26]<-(mean(data.discontent$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[27]<-(mean(data.discontent$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[28]<-(mean(data.discontent$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[29]<-(mean(data.discontent$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[30]<-(mean(data.discontent$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[31]<-(mean(data.discontent$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[32]<-(mean(data.discontent$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[33]<-(mean(data.discontent$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[34]<-(mean(data.discontent$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[35]<-(mean(data.discontent$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[36]<-(mean(data.discontent$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[37]<-(mean(data.discontent$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[38]<-(mean(data.discontent$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[39]<-(mean(data.discontent$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)
output$stdmean[40]<-(mean(data.supporter$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[41]<-(mean(data.supporter$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[42]<-(mean(data.supporter$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[43]<-(mean(data.supporter$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[44]<-(mean(data.supporter$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[45]<-(mean(data.supporter$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[46]<-(mean(data.supporter$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[47]<-(mean(data.supporter$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[48]<-(mean(data.supporter$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[49]<-(mean(data.supporter$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[50]<-(mean(data.supporter$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[51]<-(mean(data.supporter$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[52]<-(mean(data.supporter$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[53]<-(mean(data.supporter$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[54]<-(mean(data.supporter$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[55]<-(mean(data.supporter$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[56]<-(mean(data.supporter$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[57]<-(mean(data.supporter$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[58]<-(mean(data.supporter$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[59]<-(mean(data.supporter$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[60]<-(mean(data.supporter$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[61]<-(mean(data.supporter$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[62]<-(mean(data.supporter$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[63]<-(mean(data.supporter$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[64]<-(mean(data.supporter$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[65]<-(mean(data.supporter$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[66]<-(mean(data.supporter$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[67]<-(mean(data.supporter$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[68]<-(mean(data.supporter$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[69]<-(mean(data.supporter$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[70]<-(mean(data.supporter$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[71]<-(mean(data.supporter$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[72]<-(mean(data.supporter$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[73]<-(mean(data.supporter$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[74]<-(mean(data.supporter$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[75]<-(mean(data.supporter$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[76]<-(mean(data.supporter$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[77]<-(mean(data.supporter$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[78]<-(mean(data.supporter$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)

output$stdmean[79]<-(mean(data$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[80]<-(mean(data$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[81]<-(mean(data$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[82]<-(mean(data$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[83]<-(mean(data$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[84]<-(mean(data$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[85]<-(mean(data$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[86]<-(mean(data$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[87]<-(mean(data$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[88]<-(mean(data$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[89]<-(mean(data$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[90]<-(mean(data$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[91]<-(mean(data$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[92]<-(mean(data$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[93]<-(mean(data$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[94]<-(mean(data$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[95]<-(mean(data$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[96]<-(mean(data$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[97]<-(mean(data$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[98]<-(mean(data$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[99]<-(mean(data$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[100]<-(mean(data$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[101]<-(mean(data$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[102]<-(mean(data$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[103]<-(mean(data$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[104]<-(mean(data$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[105]<-(mean(data$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[106]<-(mean(data$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[107]<-(mean(data$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[108]<-(mean(data$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[109]<-(mean(data$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[110]<-(mean(data$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[111]<-(mean(data$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[112]<-(mean(data$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[113]<-(mean(data$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[114]<-(mean(data$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[115]<-(mean(data$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[116]<-(mean(data$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[117]<-(mean(data$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)

output$stdmean[118]<-(mean(data.protest$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[119]<-(mean(data.protest$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[120]<-(mean(data.protest$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[121]<-(mean(data.protest$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[122]<-(mean(data.protest$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[123]<-(mean(data.protest$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[124]<-(mean(data.protest$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[125]<-(mean(data.protest$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[126]<-(mean(data.protest$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[127]<-(mean(data.protest$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[128]<-(mean(data.protest$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[129]<-(mean(data.protest$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[130]<-(mean(data.protest$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[131]<-(mean(data.protest$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[132]<-(mean(data.protest$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[133]<-(mean(data.protest$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[134]<-(mean(data.protest$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[135]<-(mean(data.protest$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[136]<-(mean(data.protest$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[137]<-(mean(data.protest$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[138]<-(mean(data.protest$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[139]<-(mean(data.protest$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[140]<-(mean(data.protest$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[141]<-(mean(data.protest$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[142]<-(mean(data.protest$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[143]<-(mean(data.protest$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[144]<-(mean(data.protest$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[145]<-(mean(data.protest$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[146]<-(mean(data.protest$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[147]<-(mean(data.protest$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[148]<-(mean(data.protest$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[149]<-(mean(data.protest$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[150]<-(mean(data.protest$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[151]<-(mean(data.protest$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[152]<-(mean(data.protest$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[153]<-(mean(data.protest$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[154]<-(mean(data.protest$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[155]<-(mean(data.protest$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[156]<-(mean(data.protest$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)

output$stdmean[157]<-(mean(data.petition$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[158]<-(mean(data.petition$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[159]<-(mean(data.petition$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[160]<-(mean(data.petition$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[161]<-(mean(data.petition$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[162]<-(mean(data.petition$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[163]<-(mean(data.petition$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[164]<-(mean(data.petition$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[165]<-(mean(data.petition$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[166]<-(mean(data.petition$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[167]<-(mean(data.petition$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[168]<-(mean(data.petition$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[169]<-(mean(data.petition$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[170]<-(mean(data.petition$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[171]<-(mean(data.petition$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[172]<-(mean(data.petition$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[173]<-(mean(data.petition$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[174]<-(mean(data.petition$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[175]<-(mean(data.petition$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[176]<-(mean(data.petition$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[177]<-(mean(data.petition$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[178]<-(mean(data.petition$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[179]<-(mean(data.petition$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[180]<-(mean(data.petition$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[181]<-(mean(data.petition$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[182]<-(mean(data.petition$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[183]<-(mean(data.petition$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[184]<-(mean(data.petition$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[185]<-(mean(data.petition$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[186]<-(mean(data.petition$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[187]<-(mean(data.petition$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[188]<-(mean(data.petition$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[189]<-(mean(data.petition$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[190]<-(mean(data.petition$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[191]<-(mean(data.petition$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[192]<-(mean(data.petition$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[193]<-(mean(data.petition$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[194]<-(mean(data.petition$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[195]<-(mean(data.petition$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)

output$stdmean[196]<-(mean(data.meeting$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[197]<-(mean(data.meeting$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[198]<-(mean(data.meeting$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[199]<-(mean(data.meeting$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[200]<-(mean(data.meeting$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[201]<-(mean(data.meeting$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[202]<-(mean(data.meeting$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[203]<-(mean(data.meeting$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[204]<-(mean(data.meeting$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[205]<-(mean(data.meeting$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[206]<-(mean(data.meeting$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[207]<-(mean(data.meeting$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[208]<-(mean(data.meeting$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[209]<-(mean(data.meeting$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[210]<-(mean(data.meeting$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[211]<-(mean(data.meeting$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[212]<-(mean(data.meeting$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[213]<-(mean(data.meeting$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[214]<-(mean(data.meeting$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[215]<-(mean(data.meeting$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[216]<-(mean(data.meeting$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[217]<-(mean(data.meeting$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[218]<-(mean(data.meeting$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[219]<-(mean(data.meeting$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[220]<-(mean(data.meeting$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[221]<-(mean(data.meeting$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[222]<-(mean(data.meeting$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[223]<-(mean(data.meeting$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[224]<-(mean(data.meeting$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[225]<-(mean(data.meeting$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[226]<-(mean(data.meeting$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[227]<-(mean(data.meeting$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[228]<-(mean(data.meeting$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[229]<-(mean(data.meeting$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[230]<-(mean(data.meeting$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[231]<-(mean(data.meeting$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[232]<-(mean(data.meeting$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[233]<-(mean(data.meeting$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[234]<-(mean(data.meeting$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)

output$stdmean[235]<-(mean(data.ccp$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[236]<-(mean(data.ccp$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[237]<-(mean(data.ccp$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[238]<-(mean(data.ccp$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[239]<-(mean(data.ccp$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[240]<-(mean(data.ccp$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[241]<-(mean(data.ccp$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[242]<-(mean(data.ccp$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[243]<-(mean(data.ccp$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[244]<-(mean(data.ccp$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[245]<-(mean(data.ccp$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[246]<-(mean(data.ccp$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[247]<-(mean(data.ccp$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[248]<-(mean(data.ccp$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[249]<-(mean(data.ccp$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[250]<-(mean(data.ccp$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[251]<-(mean(data.ccp$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[252]<-(mean(data.ccp$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[253]<-(mean(data.ccp$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[254]<-(mean(data.ccp$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[255]<-(mean(data.ccp$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[256]<-(mean(data.ccp$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[257]<-(mean(data.ccp$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[258]<-(mean(data.ccp$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[259]<-(mean(data.ccp$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[260]<-(mean(data.ccp$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[261]<-(mean(data.ccp$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[262]<-(mean(data.ccp$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[263]<-(mean(data.ccp$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[264]<-(mean(data.ccp$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[265]<-(mean(data.ccp$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[266]<-(mean(data.ccp$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[267]<-(mean(data.ccp$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[268]<-(mean(data.ccp$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[269]<-(mean(data.ccp$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[270]<-(mean(data.ccp$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[271]<-(mean(data.ccp$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[272]<-(mean(data.ccp$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[273]<-(mean(data.ccp$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)

output$stdmean[274]<-(mean(data.selfcens$pers.h, na.rm=TRUE)-mean(data$pers.h, na.rm=TRUE))/sd(data$pers.h, na.rm=TRUE)
output$stdmean[275]<-(mean(data.selfcens$pers.h.sincerity, na.rm=TRUE)-mean(data$pers.h.sincerity, na.rm=TRUE))/sd(data$pers.h.sincerity, na.rm=TRUE)
output$stdmean[276]<-(mean(data.selfcens$pers.h.fairness, na.rm=TRUE)-mean(data$pers.h.fairness, na.rm=TRUE))/sd(data$pers.h.fairness, na.rm=TRUE)
output$stdmean[277]<-(mean(data.selfcens$pers.h.greedavoidance, na.rm=TRUE)-mean(data$pers.h.greedavoidance, na.rm=TRUE))/sd(data$pers.h.greedavoidance, na.rm=TRUE)
output$stdmean[278]<-(mean(data.selfcens$pers.h.modesty, na.rm=TRUE)-mean(data$pers.h.modesty, na.rm=TRUE))/sd(data$pers.h.modesty, na.rm=TRUE)
output$stdmean[279]<-(mean(data.selfcens$pers.e, na.rm=TRUE)-mean(data$pers.e, na.rm=TRUE))/sd(data$pers.e, na.rm=TRUE)
output$stdmean[280]<-(mean(data.selfcens$pers.e.fearfulness, na.rm=TRUE)-mean(data$pers.e.fearfulness, na.rm=TRUE))/sd(data$pers.e.fearfulness, na.rm=TRUE)
output$stdmean[281]<-(mean(data.selfcens$pers.e.anxiety, na.rm=TRUE)-mean(data$pers.e.anxiety, na.rm=TRUE))/sd(data$pers.e.anxiety, na.rm=TRUE)
output$stdmean[282]<-(mean(data.selfcens$pers.e.dependence, na.rm=TRUE)-mean(data$pers.e.dependence, na.rm=TRUE))/sd(data$pers.e.dependence, na.rm=TRUE)
output$stdmean[283]<-(mean(data.selfcens$pers.e.sentimentality, na.rm=TRUE)-mean(data$pers.e.sentimentality, na.rm=TRUE))/sd(data$pers.e.sentimentality, na.rm=TRUE)
output$stdmean[284]<-(mean(data.selfcens$pers.x, na.rm=TRUE)-mean(data$pers.x, na.rm=TRUE))/sd(data$pers.x, na.rm=TRUE)
output$stdmean[285]<-(mean(data.selfcens$pers.x.socialselfesteem, na.rm=TRUE)-mean(data$pers.x.socialselfesteem, na.rm=TRUE))/sd(data$pers.x.socialselfesteem, na.rm=TRUE)
output$stdmean[286]<-(mean(data.selfcens$pers.x.socialboldness, na.rm=TRUE)-mean(data$pers.x.socialboldness, na.rm=TRUE))/sd(data$pers.x.socialboldness, na.rm=TRUE)
output$stdmean[287]<-(mean(data.selfcens$pers.x.sociability, na.rm=TRUE)-mean(data$pers.x.sociability, na.rm=TRUE))/sd(data$pers.x.sociability, na.rm=TRUE)
output$stdmean[288]<-(mean(data.selfcens$pers.x.liveliness, na.rm=TRUE)-mean(data$pers.x.liveliness, na.rm=TRUE))/sd(data$pers.x.liveliness, na.rm=TRUE)
output$stdmean[289]<-(mean(data.selfcens$pers.a, na.rm=TRUE)-mean(data$pers.a, na.rm=TRUE))/sd(data$pers.a, na.rm=TRUE)
output$stdmean[290]<-(mean(data.selfcens$pers.a.forgiveness, na.rm=TRUE)-mean(data$pers.a.forgiveness, na.rm=TRUE))/sd(data$pers.a.forgiveness, na.rm=TRUE)
output$stdmean[291]<-(mean(data.selfcens$pers.a.gentleness, na.rm=TRUE)-mean(data$pers.a.gentleness, na.rm=TRUE))/sd(data$pers.a.gentleness, na.rm=TRUE)
output$stdmean[292]<-(mean(data.selfcens$pers.a.flexibility, na.rm=TRUE)-mean(data$pers.a.flexibility, na.rm=TRUE))/sd(data$pers.a.flexibility, na.rm=TRUE)
output$stdmean[293]<-(mean(data.selfcens$pers.a.patience, na.rm=TRUE)-mean(data$pers.a.patience, na.rm=TRUE))/sd(data$pers.a.patience, na.rm=TRUE)
output$stdmean[294]<-(mean(data.selfcens$pers.c, na.rm=TRUE)-mean(data$pers.c, na.rm=TRUE))/sd(data$pers.c, na.rm=TRUE)
output$stdmean[295]<-(mean(data.selfcens$pers.c.organization, na.rm=TRUE)-mean(data$pers.c.organization, na.rm=TRUE))/sd(data$pers.c.organization, na.rm=TRUE)
output$stdmean[296]<-(mean(data.selfcens$pers.c.diligence, na.rm=TRUE)-mean(data$pers.c.diligence, na.rm=TRUE))/sd(data$pers.c.diligence, na.rm=TRUE)
output$stdmean[297]<-(mean(data.selfcens$pers.c.perfectionism, na.rm=TRUE)-mean(data$pers.c.perfectionism, na.rm=TRUE))/sd(data$pers.c.perfectionism, na.rm=TRUE)
output$stdmean[298]<-(mean(data.selfcens$pers.c.prudence, na.rm=TRUE)-mean(data$pers.c.prudence, na.rm=TRUE))/sd(data$pers.c.prudence, na.rm=TRUE)
output$stdmean[299]<-(mean(data.selfcens$pers.o, na.rm=TRUE)-mean(data$pers.o, na.rm=TRUE))/sd(data$pers.o, na.rm=TRUE)
output$stdmean[300]<-(mean(data.selfcens$pers.o.aestheticappreciation, na.rm=TRUE)-mean(data$pers.o.aestheticappreciation, na.rm=TRUE))/sd(data$pers.o.aestheticappreciation, na.rm=TRUE)
output$stdmean[301]<-(mean(data.selfcens$pers.o.inquisitiveness, na.rm=TRUE)-mean(data$pers.o.inquisitiveness, na.rm=TRUE))/sd(data$pers.o.inquisitiveness, na.rm=TRUE)
output$stdmean[302]<-(mean(data.selfcens$pers.o.creativity, na.rm=TRUE)-mean(data$pers.o.creativity, na.rm=TRUE))/sd(data$pers.o.creativity, na.rm=TRUE)
output$stdmean[303]<-(mean(data.selfcens$pers.o.unconventionality, na.rm=TRUE)-mean(data$pers.o.unconventionality, na.rm=TRUE))/sd(data$pers.o.unconventionality, na.rm=TRUE)
output$stdmean[304]<-(mean(data.selfcens$sd3.machiavellianism, na.rm=TRUE)-mean(data$sd3.machiavellianism, na.rm=TRUE))/sd(data$sd3.machiavellianism, na.rm=TRUE)
output$stdmean[305]<-(mean(data.selfcens$sd3.narcissism, na.rm=TRUE)-mean(data$sd3.narcissism, na.rm=TRUE))/sd(data$sd3.narcissism, na.rm=TRUE)
output$stdmean[306]<-(mean(data.selfcens$sd3.psychopathy, na.rm=TRUE)-mean(data$sd3.psychopathy, na.rm=TRUE))/sd(data$sd3.psychopathy, na.rm=TRUE)
output$stdmean[307]<-(mean(data.selfcens$sdo.dominance, na.rm=TRUE)-mean(data$sdo.dominance, na.rm=TRUE))/sd(data$sdo.dominance, na.rm=TRUE)
output$stdmean[308]<-(mean(data.selfcens$sdo.antiegalitarianism, na.rm=TRUE)-mean(data$sdo.antiegalitarianism, na.rm=TRUE))/sd(data$sdo.antiegalitarianism, na.rm=TRUE)
output$stdmean[309]<-(mean(data.selfcens$sdo, na.rm=TRUE)-mean(data$sdo, na.rm=TRUE))/sd(data$sdo, na.rm=TRUE)
output$stdmean[310]<-(mean(data.selfcens$ideology.freemarket, na.rm=TRUE)-mean(data$ideology.freemarket, na.rm=TRUE))/sd(data$ideology.freemarket, na.rm=TRUE)
output$stdmean[311]<-(mean(data.selfcens$ideology.democracy, na.rm=TRUE)-mean(data$ideology.democracy, na.rm=TRUE))/sd(data$ideology.democracy, na.rm=TRUE)
output$stdmean[312]<-(mean(data.selfcens$rtotal.correct, na.rm=TRUE)-mean(data$rtotal.correct, na.rm=TRUE))/sd(data$rtotal.correct, na.rm=TRUE)

t.test(data.selfcens$pers.h, data.discontent$pers.h, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.h.sincerity, data.discontent$pers.h.sincerity, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.h.fairness, data.discontent$pers.h.fairness, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.h.greedavoidance, data.discontent$pers.h.greedavoidance, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.h.modesty, data.discontent$pers.h, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.e, data.discontent$pers.e, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.e.fearfulness, data.discontent$pers.e.fearfulness, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.e.anxiety, data.discontent$pers.e.anxiety, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.e.dependence, data.discontent$pers.e.dependence, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.e.sentimentality, data.discontent$pers.e.sentimentality, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.x, data.discontent$pers.x, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.x.socialselfesteem, data.discontent$pers.x.socialselfesteem, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.x.socialboldness, data.discontent$pers.x.socialboldness, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.x.sociability, data.discontent$pers.x.sociability, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.x.liveliness, data.discontent$pers.x.liveliness, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.a, data.discontent$pers.a, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.a.forgiveness, data.discontent$pers.a.forgiveness, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.a.gentleness, data.discontent$pers.a.gentleness, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.a.flexibility, data.discontent$pers.a.flexibility, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.a.patience, data.discontent$pers.a.patience, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.c, data.discontent$pers.c, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.c.organization, data.discontent$pers.c.organization, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.c.diligence, data.discontent$pers.c.diligence, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.c.perfectionism, data.discontent$pers.c.perfectionism, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.c.prudence, data.discontent$pers.c.prudence, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.o, data.discontent$pers.o, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.o.aestheticappreciation, data.discontent$pers.o.aestheticappreciation, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.o.inquisitiveness, data.discontent$pers.o.inquisitiveness, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.o.creativity, data.discontent$pers.o.creativity, alternative = "two.sided", var.equal = FALSE)
t.test(data.selfcens$pers.o.unconventionality, data.discontent$pers.o.unconventionality, alternative = "two.sided", var.equal = FALSE)

output$l95ci<-output$mean-1.96*output$se
output$u95ci<-output$mean+1.96*output$se

output.radar<-output[,c(1,2,8)]
radar.pers.h<-subset(output.radar, output.radar$measure=="pers.h")
radar.pers.h.sincerity<-subset(output.radar, output.radar$measure=="pers.h.sincerity")
radar.pers.h.fairness<-subset(output.radar, output.radar$measure=="pers.h.fairness")
radar.pers.h.greedavoidance<-subset(output.radar, output.radar$measure=="pers.h.greedavoidance")
radar.pers.h.modesty<-subset(output.radar, output.radar$measure=="pers.h.modesty")
radar.pers.e<-subset(output.radar, output.radar$measure=="pers.e")
radar.pers.e.fearfulness<-subset(output.radar, output.radar$measure=="pers.e.fearfulness")
radar.pers.e.anxiety<-subset(output.radar, output.radar$measure=="pers.e.anxiety")
radar.pers.e.dependence<-subset(output.radar, output.radar$measure=="pers.e.dependence")
radar.pers.e.sentimentality<-subset(output.radar, output.radar$measure=="pers.e.sentimentality")
radar.pers.x<-subset(output.radar, output.radar$measure=="pers.x")
radar.pers.x.socialselfesteem<-subset(output.radar, output.radar$measure=="pers.x.socialselfesteem")
radar.pers.x.socialboldness<-subset(output.radar, output.radar$measure=="pers.x.socialboldness")
radar.pers.x.sociability<-subset(output.radar, output.radar$measure=="pers.x.sociability")
radar.pers.x.liveliness<-subset(output.radar, output.radar$measure=="pers.x.liveliness")
radar.pers.a<-subset(output.radar, output.radar$measure=="pers.a")
radar.pers.a.forgiveness<-subset(output.radar, output.radar$measure=="pers.a.forgiveness")
radar.pers.a.gentleness<-subset(output.radar, output.radar$measure=="pers.a.gentleness")
radar.pers.a.flexibility<-subset(output.radar, output.radar$measure=="pers.a.flexibility")
radar.pers.a.patience<-subset(output.radar, output.radar$measure=="pers.a.patience")
radar.pers.c<-subset(output.radar, output.radar$measure=="pers.c")
radar.pers.c.organization<-subset(output.radar, output.radar$measure=="pers.c.organization")
radar.pers.c.diligence<-subset(output.radar, output.radar$measure=="pers.c.diligence")
radar.pers.c.perfectionism<-subset(output.radar, output.radar$measure=="pers.c.perfectionism")
radar.pers.c.prudence<-subset(output.radar, output.radar$measure=="pers.c.prudence")
radar.pers.o<-subset(output.radar, output.radar$measure=="pers.o")
radar.pers.o.aestheticappreciation<-subset(output.radar, output.radar$measure=="pers.o.aestheticappreciation")
radar.pers.o.inquisitiveness<-subset(output.radar, output.radar$measure=="pers.o.inquisitiveness")
radar.pers.o.creativity<-subset(output.radar, output.radar$measure=="pers.o.creativity")
radar.pers.o.unconventionality<-subset(output.radar, output.radar$measure=="pers.o.unconventionality")
radar.sd3.machiavellianism<-subset(output.radar, output.radar$measure=="sd3.machiavellianism")
radar.sd3.narcissism<-subset(output.radar, output.radar$measure=="sd3.narcissism")
radar.sd3.psychopathy<-subset(output.radar, output.radar$measure=="sd3.psychopathy")
radar.sdo.dominance<-subset(output.radar, output.radar$measure=="sdo.dominance")
radar.sdo.antiegalitarianism<-subset(output.radar, output.radar$measure=="sdo.antiegalitarianism")
radar.sdo<-subset(output.radar, output.radar$measure=="sdo")
radar.ideology.freemarket<-subset(output.radar, output.radar$measure=="ideology.freemarket")
radar.ideology.democracy<-subset(output.radar, output.radar$measure=="ideology.democracy")
radar.rtotal.correct<-subset(output.radar, output.radar$measure=="rtotal.correct")

radar<-cbind(radar.pers.h,	radar.pers.h.sincerity	,	radar.pers.h.fairness	,	radar.pers.h.greedavoidance	,	radar.pers.h.modesty	,	radar.pers.e	,	radar.pers.e.fearfulness	,	radar.pers.e.anxiety	,	radar.pers.e.dependence	,	radar.pers.e.sentimentality	,	radar.pers.x	,	radar.pers.x.socialselfesteem	,	radar.pers.x.socialboldness	,	radar.pers.x.sociability	,	radar.pers.x.liveliness	,	radar.pers.a	,	radar.pers.a.forgiveness	,	radar.pers.a.gentleness	,	radar.pers.a.flexibility	,	radar.pers.a.patience	,	radar.pers.c	,	radar.pers.c.organization	,	radar.pers.c.diligence	,	radar.pers.c.perfectionism	,	radar.pers.c.prudence	,	radar.pers.o	,	radar.pers.o.aestheticappreciation	,	radar.pers.o.inquisitiveness	,	radar.pers.o.creativity	,	radar.pers.o.unconventionality	,	radar.sd3.machiavellianism	,	radar.sd3.narcissism	,	radar.sd3.psychopathy	,	radar.sdo.dominance	,	radar.sdo.antiegalitarianism	,	radar.sdo	,	radar.ideology.freemarket	,	radar.ideology.democracy	,	radar.rtotal.correct)
radar<-radar[,c(1,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117)]
colnames(radar)<-c("group","honesty-humility","sincerity","fairness","greed avoidance","modesty","emotionality","fearfulness","anxiety","dependence","sentimentality","extraversion","social self-esteem","social boldness","sociability","liveliness","agreeableness","forgiveness","gentleness","flexibility","patience","conscientiousness","organization","diligence","perfectionism","prudence","openness to experience","aesthetic appreciation","inquisitiveness","creativity","unconventionality","machiavellianism","narcissism","psychopathy","dominance","anti-egalitarianism","social dominance orientation","pro-market","pro-democracy","ravens")

radar<-radar[,c(1,3:6,8:11,13:16,18:21,23:26,28:31)]

radar.discontent<-subset(radar, radar$group=="Discontent")
radar.protestor<-subset(radar, radar$group=="Protestor")
radar.petitioner<-subset(radar, radar$group=="Petitioner")
radar.ccp<-subset(radar, radar$group=="CCP Member")
radar.sampleaverage<-subset(radar, radar$group=="Sample Average")
radar.falsifier<-subset(radar, radar$group=="Falsifier")


pdf('fig-cpt-radarfull-discontent.pdf', width=9, height=9)
d=data.frame(x=c(4.5,4.5,5.5,5.5,5.5,5.5,6.5,6.5,6.5,6.5,7.5,7.5,7.5,7.5,8.5,8.5,8.5,8.5,9.5,9.5,9.5,9.5,10.5,10.5,10.5,10.5,11.5,11.5,11.5,11.5,12.5,12.5,12.5,12.5,13.5,13.5,13.5,13.5,14.5,14.5,14.5,14.5,15.5,15.5,15.5,15.5,16.5,16.5,16.5,16.5,17.5,17.5,17.5,17.5,18.5,18.5,18.5,18.5,19.5,19.5,19.5,19.5,20.5,20.5,20.5,20.5,21.5,21.5,21.5,21.5,22.5,22.5,22.5,22.5,23.5,23.5,23.5,23.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,2.5,2.5,2.5,2.5,3.5,3.5,3.5,3.5,4.5,4.5), y=c(-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5), t=c('Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility'))
ggRadar(data=radar.discontent,rescale=FALSE,interactive=FALSE,ylim=c(-.5,.5),label.gridline.min = TRUE, alpha=0,labels=TRUE, col="grey50",breaks=c(-.5,0,.5))  + theme(panel.border = element_blank()) +geom_polygon(data=d, mapping=aes(x=x, y=y, group=t,fill=t), alpha=.2)  + scale_fill_manual(values=c("#e78ac3","#a6d854","#fc8d62","#8da0cb","#66c2a5","#ffd92f")) + theme(axis.title.x=element_blank(),axis.ticks.x=element_blank()) + theme(axis.title.y=element_blank(),axis.text.y=element_blank()) + ggtitle("Discontents (n=106)") + theme_minimal()  + theme(plot.title=element_text(hjust=0, vjust=-4.5, size=20))  + theme(axis.text.y = element_text(vjust=-0.5))  + scale_y_continuous(minor_breaks = c(0), limits=c(-.5,.5))   + theme(legend.position="none") + theme(panel.grid.minor = element_line(colour = "black")) +  theme(axis.text.y= element_text(hjust=7.5))  +  theme(axis.text.x= element_text(size=11))
dev.off() 

pdf('fig-cpt-radarfull-ccpmember.pdf', width=9, height=9)
d=data.frame(x=c(4.5,4.5,5.5,5.5,5.5,5.5,6.5,6.5,6.5,6.5,7.5,7.5,7.5,7.5,8.5,8.5,8.5,8.5,9.5,9.5,9.5,9.5,10.5,10.5,10.5,10.5,11.5,11.5,11.5,11.5,12.5,12.5,12.5,12.5,13.5,13.5,13.5,13.5,14.5,14.5,14.5,14.5,15.5,15.5,15.5,15.5,16.5,16.5,16.5,16.5,17.5,17.5,17.5,17.5,18.5,18.5,18.5,18.5,19.5,19.5,19.5,19.5,20.5,20.5,20.5,20.5,21.5,21.5,21.5,21.5,22.5,22.5,22.5,22.5,23.5,23.5,23.5,23.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,2.5,2.5,2.5,2.5,3.5,3.5,3.5,3.5,4.5,4.5), y=c(-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5), t=c('Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility'))
ggRadar(data=radar.ccp,rescale=FALSE,interactive=FALSE,ylim=c(-.5,.5),label.gridline.min = TRUE, alpha=0,labels=TRUE, col="grey50",breaks=c(-.5,0,.5))  + theme(panel.border = element_blank()) +geom_polygon(data=d, mapping=aes(x=x, y=y, group=t,fill=t), alpha=.2)  + scale_fill_manual(values=c("#e78ac3","#a6d854","#fc8d62","#8da0cb","#66c2a5","#ffd92f")) + theme(axis.title.x=element_blank(),axis.ticks.x=element_blank()) + theme(axis.title.y=element_blank(),axis.text.y=element_blank()) + ggtitle("CCP Members (n=591)") + theme_minimal()  + theme(plot.title=element_text(hjust=0, vjust=-4.5, size=20))  + theme(axis.text.y = element_text(vjust=-0.5))  + scale_y_continuous(minor_breaks = c(0), limits=c(-.5,.5))   + theme(legend.position="none") + theme(panel.grid.minor = element_line(colour = "black")) +  theme(axis.text.y= element_text(hjust=7.5))  +  theme(axis.text.x= element_text(size=11))
dev.off()

pdf('fig-cpt-radarfull-protestor.pdf', width=9, height=9)
d=data.frame(x=c(4.5,4.5,5.5,5.5,5.5,5.5,6.5,6.5,6.5,6.5,7.5,7.5,7.5,7.5,8.5,8.5,8.5,8.5,9.5,9.5,9.5,9.5,10.5,10.5,10.5,10.5,11.5,11.5,11.5,11.5,12.5,12.5,12.5,12.5,13.5,13.5,13.5,13.5,14.5,14.5,14.5,14.5,15.5,15.5,15.5,15.5,16.5,16.5,16.5,16.5,17.5,17.5,17.5,17.5,18.5,18.5,18.5,18.5,19.5,19.5,19.5,19.5,20.5,20.5,20.5,20.5,21.5,21.5,21.5,21.5,22.5,22.5,22.5,22.5,23.5,23.5,23.5,23.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,2.5,2.5,2.5,2.5,3.5,3.5,3.5,3.5,4.5,4.5), y=c(-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5), t=c('Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility'))
ggRadar(data=radar.protestor,rescale=FALSE,interactive=FALSE,ylim=c(-.5,.5),label.gridline.min = TRUE, alpha=0,labels=TRUE, col="grey50",breaks=c(-.5,0,.5))  + theme(panel.border = element_blank()) +geom_polygon(data=d, mapping=aes(x=x, y=y, group=t,fill=t), alpha=.2)  + scale_fill_manual(values=c("#e78ac3","#a6d854","#fc8d62","#8da0cb","#66c2a5","#ffd92f")) + theme(axis.title.x=element_blank(),axis.ticks.x=element_blank()) + theme(axis.title.y=element_blank(),axis.text.y=element_blank()) + ggtitle("Protestors (n=180)") + theme_minimal()  + theme(plot.title=element_text(hjust=0, vjust=-4.5, size=20))  + theme(axis.text.y = element_text(vjust=-0.5))  + scale_y_continuous(minor_breaks = c(0), limits=c(-.5,.5))   + theme(legend.position="none") + theme(panel.grid.minor = element_line(colour = "black")) +  theme(axis.text.y= element_text(hjust=7.5))  +  theme(axis.text.x= element_text(size=11))
dev.off()

pdf('fig-cpt-radarfull-petitioner.pdf', width=9, height=9)
d=data.frame(x=c(4.5,4.5,5.5,5.5,5.5,5.5,6.5,6.5,6.5,6.5,7.5,7.5,7.5,7.5,8.5,8.5,8.5,8.5,9.5,9.5,9.5,9.5,10.5,10.5,10.5,10.5,11.5,11.5,11.5,11.5,12.5,12.5,12.5,12.5,13.5,13.5,13.5,13.5,14.5,14.5,14.5,14.5,15.5,15.5,15.5,15.5,16.5,16.5,16.5,16.5,17.5,17.5,17.5,17.5,18.5,18.5,18.5,18.5,19.5,19.5,19.5,19.5,20.5,20.5,20.5,20.5,21.5,21.5,21.5,21.5,22.5,22.5,22.5,22.5,23.5,23.5,23.5,23.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,2.5,2.5,2.5,2.5,3.5,3.5,3.5,3.5,4.5,4.5), y=c(-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5), t=c('Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility'))
ggRadar(data=radar.petitioner,rescale=FALSE,interactive=FALSE,ylim=c(-.5,.5),label.gridline.min = TRUE, alpha=0,labels=TRUE, col="grey50",breaks=c(-.5,0,.5))  + theme(panel.border = element_blank()) +geom_polygon(data=d, mapping=aes(x=x, y=y, group=t,fill=t), alpha=.2)  + scale_fill_manual(values=c("#e78ac3","#a6d854","#fc8d62","#8da0cb","#66c2a5","#ffd92f")) + theme(axis.title.x=element_blank(),axis.ticks.x=element_blank()) + theme(axis.title.y=element_blank(),axis.text.y=element_blank()) + ggtitle("Petitioners (n=220)") + theme_minimal()  + theme(plot.title=element_text(hjust=0, vjust=-4.5, size=20))  + theme(axis.text.y = element_text(vjust=-0.5))  + scale_y_continuous(minor_breaks = c(0), limits=c(-.5,.5))   + theme(legend.position="none") + theme(panel.grid.minor = element_line(colour = "black")) +  theme(axis.text.y= element_text(hjust=7.5))  +  theme(axis.text.x= element_text(size=11))
dev.off()

pdf('fig-cpt-radarfull-falsifier.pdf', width=9, height=9)
d=data.frame(x=c(4.5,4.5,5.5,5.5,5.5,5.5,6.5,6.5,6.5,6.5,7.5,7.5,7.5,7.5,8.5,8.5,8.5,8.5,9.5,9.5,9.5,9.5,10.5,10.5,10.5,10.5,11.5,11.5,11.5,11.5,12.5,12.5,12.5,12.5,13.5,13.5,13.5,13.5,14.5,14.5,14.5,14.5,15.5,15.5,15.5,15.5,16.5,16.5,16.5,16.5,17.5,17.5,17.5,17.5,18.5,18.5,18.5,18.5,19.5,19.5,19.5,19.5,20.5,20.5,20.5,20.5,21.5,21.5,21.5,21.5,22.5,22.5,22.5,22.5,23.5,23.5,23.5,23.5,.5,.5,.5,.5,1.5,1.5,1.5,1.5,2.5,2.5,2.5,2.5,3.5,3.5,3.5,3.5,4.5,4.5), y=c(-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5,-.5,.5,.5,-.5), t=c('Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Emotionality','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Extraversion','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Agreeableness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Conscientiousness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Openness','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility','Honesty-Humility'))
ggRadar(data=radar.falsifier,rescale=FALSE,interactive=FALSE,ylim=c(-.5,.5),label.gridline.min = TRUE, alpha=0,labels=TRUE, col="grey50",breaks=c(-.5,0,.5))  + theme(panel.border = element_blank()) +geom_polygon(data=d, mapping=aes(x=x, y=y, group=t,fill=t), alpha=.2)  + scale_fill_manual(values=c("#e78ac3","#a6d854","#fc8d62","#8da0cb","#66c2a5","#ffd92f")) + theme(axis.title.x=element_blank(),axis.ticks.x=element_blank()) + theme(axis.title.y=element_blank(),axis.text.y=element_blank()) + ggtitle("Self-censoring Respondents (n=97)") + theme_minimal()  + theme(plot.title=element_text(hjust=0, vjust=-4.5, size=20))  + theme(axis.text.y = element_text(vjust=-0.5))  + scale_y_continuous(minor_breaks = c(0), limits=c(-.5,.5))   + theme(legend.position="none") + theme(panel.grid.minor = element_line(colour = "black")) +  theme(axis.text.y= element_text(hjust=7.5))  +  theme(axis.text.x= element_text(size=11))
dev.off()

a.out.cpt<-a.out
data.cpt<-data

rm(list=setdiff(ls(), c("a.out.cpt","data.cpt")))

######BEIJING STUDENT SURVEY######

###LOAD DATA###

data.bss <- read.dta13("Beijing University Student Survey 2019_Rory.dta")# nonint.factors= TRUE, generate.factors=TRUE)
data.bss.addvar <- read.dta13("Beijing University Student Survey 2019_Rory V2.dta")# nonint.factors= TRUE, generate.factors=TRUE)
data.bss<-merge(data.bss, data.bss.addvar, by="ID")

###GENERATE BASIC VARIABLES###

##Demographics##

#female
data.bss$female<-NA
data.bss$female[data.bss$B1=="1"]<-1
data.bss$female[data.bss$B1=="2"]<-0
summary(data.bss$female)
sd(data.bss$female, na.rm=TRUE)

#age
data.bss$B2
data.bss$age<-2018-data.bss$B2 
summary(data.bss$age)
sd(data.bss$age, na.rm=TRUE)

#minority
data.bss$minority<-NA
data.bss$minority[data.bss$B3=="1"]<-0
data.bss$minority[data.bss$B3=="2"]<-1
summary(data.bss$minority)
sd(data.bss$minority, na.rm=TRUE)

#edulevels
data.bss$B3a
data.bss$edu.univ<-NA
data.bss$edu.univ[data.bss$B3a=="1"]<-1
data.bss$edu.univ[data.bss$B3a=="2"]<-0
data.bss$edu.univ[data.bss$B3a=="3"]<-0
summary(data.bss$edu.univ)
sd(data.bss$edu.univ, na.rm=TRUE)

data.bss$B3a
data.bss$edu.maphd<-NA
data.bss$edu.maphd[data.bss$B3a=="1"]<-0
data.bss$edu.maphd[data.bss$B3a=="2"]<-1
data.bss$edu.maphd[data.bss$B3a=="3"]<-1
summary(data.bss$edu.maphd)
sd(data.bss$edu.maphd, na.rm=TRUE)

#par.edulevels
data.bss$B10
data.bss$par.edu.univ<-NA
data.bss$par.edu.univ[data.bss$B10=="1"]<-0
data.bss$par.edu.univ[data.bss$B10=="2"]<-0
data.bss$par.edu.univ[data.bss$B10=="3"]<-0
data.bss$par.edu.univ[data.bss$B10=="4"]<-0
data.bss$par.edu.univ[data.bss$B10=="5"]<-1
data.bss$par.edu.univ[data.bss$B10=="6"]<-0
data.bss$par.edu.univ[data.bss$B10=="7"]<-0
summary(data.bss$par.edu.univ)

data.bss$B10
data.bss$par.edu.maphd<-NA
data.bss$par.edu.maphd[data.bss$B10=="1"]<-0
data.bss$par.edu.maphd[data.bss$B10=="2"]<-0
data.bss$par.edu.maphd[data.bss$B10=="3"]<-0
data.bss$par.edu.maphd[data.bss$B10=="4"]<-0
data.bss$par.edu.maphd[data.bss$B10=="5"]<-0
data.bss$par.edu.maphd[data.bss$B10=="6"]<-1
data.bss$par.edu.maphd[data.bss$B10=="7"]<-1
summary(data.bss$par.edu.maphd)

#major
data.bss$B3b
data.bss$major<-NA
data.bss$major[data.bss$B3b=="1"]<-"Science"
data.bss$major[data.bss$B3b=="2"]<-"Engineering"
data.bss$major[data.bss$B3b=="3"]<-"Economics"
data.bss$major[data.bss$B3b=="4"]<-"Management"
data.bss$major[data.bss$B3b=="5"]<-"Law"
data.bss$major[data.bss$B3b=="6"]<-"Other" #Chinese has been corrupted
ftable(data.bss$major)

#fam.econstatus
data.bss$B6 
data.bss$fam.econstatus<-data.bss$B6
ftable(data.bss$fam.econstatus)

#fam.econdir
data.bss$B7 
data.bss$fam.econdir<-6-data.bss$B7
ftable(data.bss$fam.econdir)

#fam.income
data.bss$B14 
data.bss$fam.income<-as.numeric(paste(data.bss$B14)) 
hist(data.bss$fam.income)

#buy.computer
data.bss$buy.computer<-NA
data.bss$buy.computer[data.bss$B12=="1"]<-1
data.bss$buy.computer[data.bss$B12=="2"]<-0
summary(data.bss$buy.computer) #Almost 96%

#buy.cell
data.bss$buy.cell<-NA
data.bss$buy.cell[data.bss$B13=="1"]<-1
data.bss$buy.cell[data.bss$B13=="2"]<-0
summary(data.bss$buy.cell) #Almost 100%

#lifesat
data.bss$B8 
data.bss$lifesat<-6-data.bss$B8
ftable(data.bss$lifesat)

#ccp 
data.bss$ccp<-NA
data.bss$ccp[data.bss$D1a=="1"]<-1
data.bss$ccp[data.bss$D1a=="2"]<-0
summary(data.bss$ccp) 
sd(data.bss$ccp, na.rm=TRUE)
ftable(data.bss$ccp)

#ccp.year
data.bss$ccp.year<-NA
data.bss$ccp.year<-as.numeric(data.bss$D1b) 
summary(data.bss$ccp.year) 

#ccp.applied
data.bss$ccp.applied<-NA
data.bss$ccp.applied[data.bss$D1c=="1"]<-1
data.bss$ccp.applied[data.bss$D1c=="2"]<-0
summary(data.bss$ccp.applied)

#party.mem
data.bss$party.mem<-NA
data.bss$party.mem<-"non member"
data.bss$party.mem[data.bss$ccp=="1"]<-"member"
data.bss$party.mem[data.bss$ccp.applied=="1"]<-"rejected applicant"
ftable(data.bss$party.mem)

#sat.central
data.bss$sat.central<-NA
data.bss$sat.central[data.bss$E6a=="11"]<-NA 
data.bss$sat.central[data.bss$E6a=="10"]<-10
data.bss$sat.central[data.bss$E6a=="9"]<-9
data.bss$sat.central[data.bss$E6a=="8"]<-8
data.bss$sat.central[data.bss$E6a=="7"]<-7
data.bss$sat.central[data.bss$E6a=="6"]<-6
data.bss$sat.central[data.bss$E6a=="5"]<-5
data.bss$sat.central[data.bss$E6a=="4"]<-4
data.bss$sat.central[data.bss$E6a=="3"]<-3
data.bss$sat.central[data.bss$E6a=="2"]<-2
data.bss$sat.central[data.bss$E6a=="1"]<-1
data.bss$sat.central[data.bss$E6a=="0"]<-0
ftable(data.bss$sat.central)
hist(data.bss$sat.central)
summary(data.bss$sat.central)

#sat.local
data.bss$sat.local<-NA
data.bss$sat.local[data.bss$E6b=="11"]<-NA 
data.bss$sat.local[data.bss$E6b=="10"]<-10
data.bss$sat.local[data.bss$E6b=="9"]<-9
data.bss$sat.local[data.bss$E6b=="8"]<-8
data.bss$sat.local[data.bss$E6b=="7"]<-7
data.bss$sat.local[data.bss$E6b=="6"]<-6
data.bss$sat.local[data.bss$E6b=="5"]<-5
data.bss$sat.local[data.bss$E6b=="4"]<-4
data.bss$sat.local[data.bss$E6b=="3"]<-3
data.bss$sat.local[data.bss$E6b=="2"]<-2
data.bss$sat.local[data.bss$E6b=="1"]<-1
data.bss$sat.local[data.bss$E6b=="0"]<-0
ftable(data.bss$sat.local)
hist(data.bss$sat.local)
summary(data.bss$sat.local)
sd(data.bss$sat.local, na.rm=TRUE)

#discontent 
data.bss$discontent<-NA
data.bss$discontent[data.bss$sat.central=="10"]<-0
data.bss$discontent[data.bss$sat.central=="9"]<-0
data.bss$discontent[data.bss$sat.central=="8"]<-0
data.bss$discontent[data.bss$sat.central=="7"]<-0
data.bss$discontent[data.bss$sat.central=="6"]<-0
data.bss$discontent[data.bss$sat.central=="5"]<-0
data.bss$discontent[data.bss$sat.central=="4"]<-1
data.bss$discontent[data.bss$sat.central=="3"]<-1
data.bss$discontent[data.bss$sat.central=="2"]<-1
data.bss$discontent[data.bss$sat.central=="1"]<-1
data.bss$discontent[data.bss$sat.central=="0"]<-1
summary(data.bss$discontent, na.rm=TRUE)
sd(data.bss$discontent, na.rm=TRUE)
ftable(data.bss$discontent)

data.bss$discontent.alt<-NA
data.bss$discontent.alt[data.bss$sat.central=="10"]<-0
data.bss$discontent.alt[data.bss$sat.central=="9"]<-0
data.bss$discontent.alt[data.bss$sat.central=="8"]<-0
data.bss$discontent.alt[data.bss$sat.central=="7"]<-0
data.bss$discontent.alt[data.bss$sat.central=="6"]<-1
data.bss$discontent.alt[data.bss$sat.central=="5"]<-1
data.bss$discontent.alt[data.bss$sat.central=="4"]<-1
data.bss$discontent.alt[data.bss$sat.central=="3"]<-1
data.bss$discontent.alt[data.bss$sat.central=="2"]<-1
data.bss$discontent.alt[data.bss$sat.central=="1"]<-1
data.bss$discontent.alt[data.bss$sat.central=="0"]<-1
summary(data.bss$discontent.alt, na.rm=TRUE)
sd(data.bss$discontent.alt, na.rm=TRUE)
ftable(data.bss$discontent.alt)

##Personality##
data.bss$H1n<-6-as.numeric(as.character(data.bss$D2V21)) 
data.bss$H2n<-as.numeric(as.character(data.bss$D2V1))
data.bss$H3n<-as.numeric(as.character(data.bss$D2V22))
data.bss$H4n<-as.numeric(as.character(data.bss$D2V41))
data.bss$H5n<-as.numeric(as.character(data.bss$D2V23))
data.bss$H6n<-as.numeric(as.character(data.bss$D2V24))
data.bss$H7n<-as.numeric(as.character(data.bss$D2V42))
data.bss$H8n<-as.numeric(as.character(data.bss$D2V2))
data.bss$H9n<-6-as.numeric(as.character(data.bss$D2V3))
data.bss$H10n<-6-as.numeric(as.character(data.bss$D2V4))
data.bss$H11n<-as.numeric(as.character(data.bss$D2V25))
data.bss$H12n<-6-as.numeric(as.character(data.bss$D2V43))
data.bss$H13n<-as.numeric(as.character(data.bss$D2V44))
data.bss$H14n<-6-as.numeric(as.character(data.bss$D2V26))
data.bss$H15n<-6-as.numeric(as.character(data.bss$D2V45))
data.bss$H16n<-as.numeric(as.character(data.bss$D2V46))
data.bss$H17n<-as.numeric(as.character(data.bss$D2V27))
data.bss$H18n<-as.numeric(as.character(data.bss$D2V5))
data.bss$H19n<-6-as.numeric(as.character(data.bss$D2V28))
data.bss$H20n<-6-as.numeric(as.character(data.bss$D2V6))
data.bss$H21n<-6-as.numeric(as.character(data.bss$D2V47))
data.bss$H22n<-as.numeric(as.character(data.bss$D2V29))
data.bss$H23n<-as.numeric(as.character(data.bss$D2V30))
data.bss$H24n<-as.numeric(as.character(data.bss$D2V7))
data.bss$H25n<-as.numeric(as.character(data.bss$D2V8))
data.bss$H26n<-6-as.numeric(as.character(data.bss$D2V48))
data.bss$H27n<-as.numeric(as.character(data.bss$D2V31))
data.bss$H28n<-6-as.numeric(as.character(data.bss$D2V32))
data.bss$H29n<-as.numeric(as.character(data.bss$D2V9))
data.bss$H30n<-6-as.numeric(as.character(data.bss$D2V49))
data.bss$H31n<-6-as.numeric(as.character(data.bss$D2V10))
data.bss$H32n<-6-as.numeric(as.character(data.bss$D2V11))
data.bss$H33n<-as.numeric(as.character(data.bss$D2V12))
data.bss$H34n<-as.numeric(as.character(data.bss$D2V13))
data.bss$H35n<-6-as.numeric(as.character(data.bss$D2V33))
data.bss$H36n<-as.numeric(as.character(data.bss$D2V50))
data.bss$H37n<-as.numeric(as.character(data.bss$D2V34))
data.bss$H38n<-as.numeric(as.character(data.bss$D2V51))
data.bss$H39n<-as.numeric(as.character(data.bss$D2V14))
data.bss$H40n<-as.numeric(as.character(data.bss$D2V52))
data.bss$H41n<-6-as.numeric(as.character(data.bss$D2V15))
data.bss$H42n<-6-as.numeric(as.character(data.bss$D2V16))
data.bss$H43n<-as.numeric(as.character(data.bss$D2V35))
data.bss$H44n<-6-as.numeric(as.character(data.bss$D2V53))
data.bss$H45n<-as.numeric(as.character(data.bss$D2V54))
data.bss$H46n<-6-as.numeric(as.character(data.bss$D2V36))
data.bss$H47n<-as.numeric(as.character(data.bss$D2V37))
data.bss$H48n<-6-as.numeric(as.character(data.bss$D2V55))
data.bss$H49n<-6-as.numeric(as.character(data.bss$D2V56))
data.bss$H50n<-as.numeric(as.character(data.bss$D2V38))
data.bss$H51n<-as.numeric(as.character(data.bss$D2V17))
data.bss$H52n<-6-as.numeric(as.character(data.bss$D2V57))
data.bss$H53n<-6-as.numeric(as.character(data.bss$D2V39))
data.bss$H54n<-as.numeric(as.character(data.bss$D2V58))
data.bss$H55n<-6-as.numeric(as.character(data.bss$D2V59))
data.bss$H56n<-6-as.numeric(as.character(data.bss$D2V40))
data.bss$H57n<-6-as.numeric(as.character(data.bss$D2V60))
data.bss$H58n<-as.numeric(as.character(data.bss$D2V18))
data.bss$H59n<-6-as.numeric(as.character(data.bss$D2V19))
data.bss$H60n<-6-as.numeric(as.character(data.bss$D2V20))

data.bss$pers.h.sincerity = ((data.bss$H6n + data.bss$H54n + data.bss$H30n)/3) 
data.bss$pers.h.fairness = ((data.bss$H12n + data.bss$H36n + data.bss$H60n)/3) 
data.bss$pers.h.greedavoidance = ((data.bss$H18n + data.bss$H42n)/2) 
data.bss$pers.h.modesty = ((data.bss$H24n + data.bss$H48n)/2)
data.bss$pers.h = ((data.bss$H6n + data.bss$H54n + data.bss$H30n + data.bss$H12n + data.bss$H36n + data.bss$H60n + data.bss$H18n + data.bss$H42n + data.bss$H24n + data.bss$H48n)/10) 

data.bss$pers.e.fearfulness = ((data.bss$H5n + data.bss$H29n + data.bss$H53n)/3)
data.bss$pers.e.anxiety = ((data.bss$H11n + data.bss$H35n)/2)
data.bss$pers.e.dependence = ((data.bss$H17n + data.bss$H41n)/2) 
data.bss$pers.e.sentimentality = ((data.bss$H23n + data.bss$H47n + data.bss$H59n)/3) 
data.bss$pers.e = ((data.bss$H5n + data.bss$H29n + data.bss$H53n + data.bss$H11n + data.bss$H35n + data.bss$H17n + data.bss$H41n + data.bss$H23n + data.bss$H47n + data.bss$H59n)/10)

data.bss$pers.x.socialselfesteem = ((data.bss$H4n + data.bss$H28n + data.bss$H52n)/3)
data.bss$pers.x.socialboldness = ((data.bss$H10n + data.bss$H34n + data.bss$H58n)/3) 
data.bss$pers.x.sociability = ((data.bss$H16n + data.bss$H40n)/2)
data.bss$pers.x.liveliness = ((data.bss$H22n + data.bss$H46n)/2) 
data.bss$pers.x = ((data.bss$H4n + data.bss$H28n + data.bss$H52n + data.bss$H10n + data.bss$H34n + data.bss$H58n + data.bss$H16n + data.bss$H40n + data.bss$H22n + data.bss$H46n)/10)

data.bss$pers.a.forgiveness = ((data.bss$H3n + data.bss$H27n)/2) 
data.bss$pers.a.gentleness = ((data.bss$H9n + data.bss$H33n + data.bss$H51n)/3) 
data.bss$pers.a.flexibility = ((data.bss$H15n + data.bss$H39n + data.bss$H57n)/3) 
data.bss$pers.a.patience = ((data.bss$H21n + data.bss$H45n)/2) 
data.bss$pers.a = ((data.bss$H3n + data.bss$H27n + data.bss$H9n + data.bss$H33n + data.bss$H51n + data.bss$H15n + data.bss$H39n + data.bss$H57n + data.bss$H21n + data.bss$H45n)/10) 

data.bss$pers.c.organization = ((data.bss$H2n + data.bss$H26n)/2) 
data.bss$pers.c.diligence = ((data.bss$H8n + data.bss$H32n)/2) 
data.bss$pers.c.perfectionism = ((data.bss$H14n + data.bss$H38n + data.bss$H50n)/3) 
data.bss$pers.c.prudence = ((data.bss$H20n + data.bss$H44n + data.bss$H56n)/3) 
data.bss$pers.c = ((data.bss$H2n + data.bss$H26n + data.bss$H8n + data.bss$H32n + data.bss$H14n + data.bss$H38n + data.bss$H50n + data.bss$H20n + data.bss$H44n + data.bss$H56n)/10) 

data.bss$pers.o.aestheticappreciation = ((data.bss$H1n + data.bss$H25n)/2) 
data.bss$pers.o.inquisitiveness = ((data.bss$H7n + data.bss$H31n)/2) 
data.bss$pers.o.creativity = ((data.bss$H13n + data.bss$H37n + data.bss$H49n)/3) 
data.bss$pers.o.unconventionality = ((data.bss$H19n + data.bss$H43n + data.bss$H55n)/3) 
data.bss$pers.o = ((data.bss$H1n + data.bss$H25n + data.bss$H7n + data.bss$H31n + data.bss$H13n + data.bss$H37n + data.bss$H49n + data.bss$H19n + data.bss$H43n + data.bss$H55n)/10) 

##Political Ideology##
data.bss$C2an<-5-as.numeric(paste(data.bss$B15a))
data.bss$C2bn<-as.numeric(paste(data.bss$B15b))+1
data.bss$C2cn<-as.numeric(paste(data.bss$B15c))+1
data.bss$C2dn<-as.numeric(paste(data.bss$B15d))+1
data.bss$C2en<-as.numeric(paste(data.bss$B15e))+1
data.bss$C2fn<-as.numeric(paste(data.bss$B9a))+1
data.bss$C2gn<-as.numeric(paste(data.bss$B9b))+1
data.bss$C2hn<-5-as.numeric(paste(data.bss$B9c))
data.bss$C2in<-as.numeric(paste(data.bss$B9d))+1
data.bss$C2jn<-as.numeric(paste(data.bss$B9e))+1
data.bss$C2kn<-5-as.numeric(paste(data.bss$B9f))

data.bss$ideology.freemarket <- (data.bss$C2an + data.bss$C2bn + data.bss$C2fn + data.bss$C2gn + data.bss$C2hn +  data.bss$C2in + data.bss$C2jn)  / 7   
data.bss$ideology.democracy <- (data.bss$C2cn + data.bss$C2dn + data.bss$C2en + data.bss$C2kn)  / 4   

summary(data.bss$ideology.freemarket)
sd(data.bss$ideology.freemarket, na.rm=TRUE)

summary(data.bss$ideology.democracy)
sd(data.bss$ideology.democracy, na.rm=TRUE)

###MULTIPLE IMPUTATION###
names(data.bss)

data.bss.mi<- data.frame(cbind(data.bss$ID, data.bss$sample_code, data.bss$sat.central, data.bss$ccp, data.bss$party.mem, data.bss$female, data.bss$minority, data.bss$H1n, data.bss$H2n, data.bss$H3n, data.bss$H4n, data.bss$H5n, data.bss$H6n, data.bss$H7n, data.bss$H8n, data.bss$H9n, data.bss$H10n, data.bss$H11n, data.bss$H12n, data.bss$H13n, data.bss$H14n, data.bss$H15n, data.bss$H16n, data.bss$H17n, data.bss$H18n, data.bss$H19n, data.bss$H20n, data.bss$H21n, data.bss$H22n, data.bss$H23n, data.bss$H24n, data.bss$H25n, data.bss$H26n, data.bss$H27n, data.bss$H28n, data.bss$H29n, data.bss$H30n, data.bss$H31n, data.bss$H32n, data.bss$H33n, data.bss$H34n, data.bss$H35n, data.bss$H36n, data.bss$H37n, data.bss$H38n, data.bss$H39n, data.bss$H40n, data.bss$H41n, data.bss$H42n, data.bss$H43n, data.bss$H44n, data.bss$H45n, data.bss$H46n, data.bss$H47n, data.bss$H48n, data.bss$H49n, data.bss$H50n, data.bss$H51n, data.bss$H52n, data.bss$H53n, data.bss$H54n, data.bss$H55n, data.bss$H56n, data.bss$H57n, data.bss$H58n, data.bss$H59n, data.bss$H60n, data.bss$C2an, data.bss$C2bn, data.bss$C2cn, data.bss$C2dn, data.bss$C2en, data.bss$C2fn, data.bss$C2gn, data.bss$C2hn, data.bss$C2in, data.bss$C2jn, data.bss$C2kn))  
colnames(data.bss.mi) <-c("id","sample_code","sat.central","ccp","party.mem","female", "minority", "H1n", "H2n", "H3n", "H4n", "H5n", "H6n", "H7n", "H8n", "H9n", "H10n", "H11n", "H12n", "H13n", "H14n", "H15n", "H16n", "H17n", "H18n", "H19n", "H20n", "H21n", "H22n", "H23n", "H24n", "H25n", "H26n", "H27n", "H28n", "H29n", "H30n", "H31n", "H32n", "H33n", "H34n", "H35n", "H36n", "H37n", "H38n", "H39n", "H40n", "H41n", "H42n", "H43n", "H44n", "H45n", "H46n", "H47n", "H48n", "H49n", "H50n", "H51n", "H52n", "H53n", "H54n", "H55n", "H56n", "H57n", "H58n", "H59n", "H60n", "C2an", "C2bn", "C2cn", "C2dn", "C2en", "C2fn", "C2gn", "C2hn", "C2in", "C2jn", "C2kn")
summary(data.bss.mi)

data.bss.mi$sat.central<-as.numeric(as.character(data.bss.mi$sat.central))
data.bss.mi$H1n<-as.numeric(as.character(data.bss.mi$H1n))
data.bss.mi$H2n<-as.numeric(as.character(data.bss.mi$H2n))
data.bss.mi$H3n<-as.numeric(as.character(data.bss.mi$H3n))
data.bss.mi$H4n<-as.numeric(as.character(data.bss.mi$H4n))
data.bss.mi$H5n<-as.numeric(as.character(data.bss.mi$H5n))
data.bss.mi$H6n<-as.numeric(as.character(data.bss.mi$H6n))
data.bss.mi$H7n<-as.numeric(as.character(data.bss.mi$H7n))
data.bss.mi$H8n<-as.numeric(as.character(data.bss.mi$H8n))
data.bss.mi$H9n<-as.numeric(as.character(data.bss.mi$H9n))
data.bss.mi$H10n<-as.numeric(as.character(data.bss.mi$H10n))
data.bss.mi$H11n<-as.numeric(as.character(data.bss.mi$H11n))
data.bss.mi$H12n<-as.numeric(as.character(data.bss.mi$H12n))
data.bss.mi$H13n<-as.numeric(as.character(data.bss.mi$H13n))
data.bss.mi$H14n<-as.numeric(as.character(data.bss.mi$H14n))
data.bss.mi$H15n<-as.numeric(as.character(data.bss.mi$H15n))
data.bss.mi$H16n<-as.numeric(as.character(data.bss.mi$H16n))
data.bss.mi$H17n<-as.numeric(as.character(data.bss.mi$H17n))
data.bss.mi$H18n<-as.numeric(as.character(data.bss.mi$H18n))
data.bss.mi$H19n<-as.numeric(as.character(data.bss.mi$H19n))
data.bss.mi$H20n<-as.numeric(as.character(data.bss.mi$H20n))
data.bss.mi$H21n<-as.numeric(as.character(data.bss.mi$H21n))
data.bss.mi$H22n<-as.numeric(as.character(data.bss.mi$H22n))
data.bss.mi$H23n<-as.numeric(as.character(data.bss.mi$H23n))
data.bss.mi$H24n<-as.numeric(as.character(data.bss.mi$H24n))
data.bss.mi$H25n<-as.numeric(as.character(data.bss.mi$H25n))
data.bss.mi$H26n<-as.numeric(as.character(data.bss.mi$H26n))
data.bss.mi$H27n<-as.numeric(as.character(data.bss.mi$H27n))
data.bss.mi$H28n<-as.numeric(as.character(data.bss.mi$H28n))
data.bss.mi$H29n<-as.numeric(as.character(data.bss.mi$H29n))
data.bss.mi$H30n<-as.numeric(as.character(data.bss.mi$H30n))
data.bss.mi$H31n<-as.numeric(as.character(data.bss.mi$H31n))
data.bss.mi$H32n<-as.numeric(as.character(data.bss.mi$H32n))
data.bss.mi$H33n<-as.numeric(as.character(data.bss.mi$H33n))
data.bss.mi$H34n<-as.numeric(as.character(data.bss.mi$H34n))
data.bss.mi$H35n<-as.numeric(as.character(data.bss.mi$H35n))
data.bss.mi$H36n<-as.numeric(as.character(data.bss.mi$H36n))
data.bss.mi$H37n<-as.numeric(as.character(data.bss.mi$H37n))
data.bss.mi$H38n<-as.numeric(as.character(data.bss.mi$H38n))
data.bss.mi$H39n<-as.numeric(as.character(data.bss.mi$H39n))
data.bss.mi$H40n<-as.numeric(as.character(data.bss.mi$H40n))
data.bss.mi$H41n<-as.numeric(as.character(data.bss.mi$H41n))
data.bss.mi$H42n<-as.numeric(as.character(data.bss.mi$H42n))
data.bss.mi$H43n<-as.numeric(as.character(data.bss.mi$H43n))
data.bss.mi$H44n<-as.numeric(as.character(data.bss.mi$H44n))
data.bss.mi$H45n<-as.numeric(as.character(data.bss.mi$H45n))
data.bss.mi$H46n<-as.numeric(as.character(data.bss.mi$H46n))
data.bss.mi$H47n<-as.numeric(as.character(data.bss.mi$H47n))
data.bss.mi$H48n<-as.numeric(as.character(data.bss.mi$H48n))
data.bss.mi$H49n<-as.numeric(as.character(data.bss.mi$H49n))
data.bss.mi$H50n<-as.numeric(as.character(data.bss.mi$H50n))
data.bss.mi$H51n<-as.numeric(as.character(data.bss.mi$H51n))
data.bss.mi$H52n<-as.numeric(as.character(data.bss.mi$H52n))
data.bss.mi$H53n<-as.numeric(as.character(data.bss.mi$H53n))
data.bss.mi$H54n<-as.numeric(as.character(data.bss.mi$H54n))
data.bss.mi$H55n<-as.numeric(as.character(data.bss.mi$H55n))
data.bss.mi$H56n<-as.numeric(as.character(data.bss.mi$H56n))
data.bss.mi$H57n<-as.numeric(as.character(data.bss.mi$H57n))
data.bss.mi$H58n<-as.numeric(as.character(data.bss.mi$H58n))
data.bss.mi$H59n<-as.numeric(as.character(data.bss.mi$H59n))
data.bss.mi$H60n<-as.numeric(as.character(data.bss.mi$H60n))

data.bss.mi$C2an<-as.numeric(as.character(data.bss.mi$C2an))
data.bss.mi$C2bn<-as.numeric(as.character(data.bss.mi$C2bn))
data.bss.mi$C2cn<-as.numeric(as.character(data.bss.mi$C2cn))
data.bss.mi$C2dn<-as.numeric(as.character(data.bss.mi$C2dn))
data.bss.mi$C2en<-as.numeric(as.character(data.bss.mi$C2en))
data.bss.mi$C2fn<-as.numeric(as.character(data.bss.mi$C2fn))
data.bss.mi$C2gn<-as.numeric(as.character(data.bss.mi$C2gn))
data.bss.mi$C2hn<-as.numeric(as.character(data.bss.mi$C2hn))
data.bss.mi$C2in<-as.numeric(as.character(data.bss.mi$C2in))
data.bss.mi$C2jn<-as.numeric(as.character(data.bss.mi$C2jn))
data.bss.mi$C2kn<-as.numeric(as.character(data.bss.mi$C2kn))

set.seed(1234)
a.out.bss <- amelia(data.bss.mi, p2s=1, m = 50, idvars = c("id","sample_code","party.mem"), noms=c("female","minority","ccp"),ords = c("sat.central","H1n", "H2n", "H3n", "H4n", "H5n", "H6n", "H7n", "H8n", "H9n", "H10n", "H11n", "H12n", "H13n", "H14n", "H15n", "H16n", "H17n", "H18n", "H19n", "H20n", "H21n", "H22n", "H23n", "H24n", "H25n", "H26n", "H27n", "H28n", "H29n", "H30n", "H31n", "H32n", "H33n", "H34n", "H35n", "H36n", "H37n", "H38n", "H39n", "H40n", "H41n", "H42n", "H43n", "H44n", "H45n", "H46n", "H47n", "H48n", "H49n", "H50n", "H51n", "H52n", "H53n", "H54n", "H55n", "H56n", "H57n", "H58n", "H59n", "H60n", "C2an", "C2bn", "C2cn", "C2dn", "C2en", "C2fn", "C2gn", "C2hn", "C2in", "C2jn", "C2kn")) #Check 
a.out.bss 
write.amelia(obj = a.out.bss, file.stem = "data.bss.m")

###CREATE VARIABLES ACROSS IMPUTED DATASETS###

a.out.bss<-transform(a.out.bss, pers.h.sincerity = ((H6n + H54n + H30n)/3)) 
a.out.bss<-transform(a.out.bss, pers.h.fairness = ((H12n + H36n + H60n)/3)) 
a.out.bss<-transform(a.out.bss, pers.h.greedavoidance = ((H18n + H42n)/2)) 
a.out.bss<-transform(a.out.bss, pers.h.modesty = ((H24n + H48n)/2)) 
a.out.bss<-transform(a.out.bss, pers.h = ((H6n + H54n + H30n + H12n + H36n + H60n + H18n + H42n + H24n + H48n)/10)) 

a.out.bss<-transform(a.out.bss, pers.e.fearfulness = ((H5n + H29n + H53n)/3)) 
a.out.bss<-transform(a.out.bss, pers.e.anxiety = ((H11n + H35n)/2)) 
a.out.bss<-transform(a.out.bss, pers.e.dependence = ((H17n + H41n)/2)) 
a.out.bss<-transform(a.out.bss, pers.e.sentimentality = ((H23n + H47n + H59n)/3)) 
a.out.bss<-transform(a.out.bss, pers.e = ((H5n + H29n + H53n + H11n + H35n + H17n + H41n + H23n + H47n + H59n)/10)) 

a.out.bss<-transform(a.out.bss, pers.x.socialselfesteem = ((H4n + H28n + H52n)/3)) 
a.out.bss<-transform(a.out.bss, pers.x.socialboldness = ((H10n + H34n + H58n)/3)) 
a.out.bss<-transform(a.out.bss, pers.x.sociability = ((H16n + H40n)/2)) 
a.out.bss<-transform(a.out.bss, pers.x.liveliness = ((H22n + H46n)/2)) 
a.out.bss<-transform(a.out.bss, pers.x = ((H4n + H28n + H52n + H10n + H34n + H58n + H16n + H40n + H22n + H46n)/10)) 

a.out.bss<-transform(a.out.bss, pers.a.forgiveness = ((H3n + H27n)/2)) 
a.out.bss<-transform(a.out.bss, pers.a.gentleness = ((H9n + H33n + H51n)/3)) 
a.out.bss<-transform(a.out.bss, pers.a.flexibility = ((H15n + H39n + H57n)/3)) 
a.out.bss<-transform(a.out.bss, pers.a.patience = ((H21n + H45n)/2)) 
a.out.bss<-transform(a.out.bss, pers.a = ((H3n + H27n + H9n + H33n + H51n + H15n + H39n + H57n + H21n + H45n)/10)) 

a.out.bss<-transform(a.out.bss, pers.c.organization = ((H2n + H26n)/2)) 
a.out.bss<-transform(a.out.bss, pers.c.diligence = ((H8n + H32n)/2)) 
a.out.bss<-transform(a.out.bss, pers.c.perfectionism = ((H14n + H38n + H50n)/3)) 
a.out.bss<-transform(a.out.bss, pers.c.prudence = ((H20n + H44n + H56n)/3)) 
a.out.bss<-transform(a.out.bss, pers.c = ((H2n + H26n + H8n + H32n + H14n + H38n + H50n + H20n + H44n + H56n)/10)) 

a.out.bss<-transform(a.out.bss, pers.o.aestheticappreciation = ((H1n + H25n)/2)) 
a.out.bss<-transform(a.out.bss, pers.o.inquisitiveness = ((H7n + H31n)/2)) 
a.out.bss<-transform(a.out.bss, pers.o.creativity = ((H13n + H37n + H49n)/3)) 
a.out.bss<-transform(a.out.bss, pers.o.unconventionality = ((H19n + H43n + H55n)/3)) 
a.out.bss<-transform(a.out.bss, pers.o = ((H1n + H25n + H7n + H31n + H13n + H37n + H49n + H19n + H43n + H55n)/10)) 

a.out.bss<-transform(a.out.bss, ideology.freemarket = ((C2an + C2bn + C2fn + C2gn + C2hn + C2in + C2jn)/7)) 
a.out.bss<-transform(a.out.bss, ideology.democracy = ((C2cn + C2dn + C2en + C2kn)/4)) 

a.out.bss<-transform(a.out.bss, discontent=ifelse(sat.central<5,1,0))
a.out.bss<-transform(a.out.bss, discontent.alt=ifelse(sat.central<7,1,0))
a.out.bss<-transform(a.out.bss, discontent.dem=ifelse(ideology.democracy>2.9999,1,0))

write.amelia(obj=a.out.bss, file.stem = "outdata")

###ANALYSIS###

#Figure: Distribution of Regime Support#

data.bar.bss<-data.frame(ftable(data.bss$sat.central))
colnames(data.bar.bss)<-c("support","frequency")
data.bar.bss$group<-"Supporter"
data.bar.bss$group[data.bar.bss$support=="4"]<-"Discontent"
data.bar.bss$group[data.bar.bss$support=="3"]<-"Discontent"
data.bar.bss$group[data.bar.bss$support=="2"]<-"Discontent"
data.bar.bss$group[data.bar.bss$support=="1"]<-"Discontent"
data.bar.bss$group[data.bar.bss$support=="0"]<-"Discontent"

write.csv(data.bar.bss, "data.bar.bss.csv")

pdf('fig-regsupport-bss.pdf', width=5.25, height=3.5)
ggplot(data.bar.bss, aes(x=support, y=frequency, colour=group, fill=group)) + geom_col(alpha=.5,width=.7) +theme_bw() + xlab("Satisfaction with Central Government") + ylab("Count")  +  geom_vline(xintercept = 5.5, size=.5, color="grey50",lty="dashed") + annotate("text", x=3, y = 150, label = "Discontents",color="grey20", size=3.75)  + annotate("text", x=3, y = 100, label = "n=89, 4.7%",color="grey20", size=3.65) + scale_color_manual(values=c("#fc8d62","grey50"),guide=FALSE, aesthetics = c("fill","color"))
dev.off()

#Figure: Personality and Regime Support#
a.mids.bss <- miceadds::datlist2mids(a.out.bss$imputations)

m1<-with(a.mids.bss, lm(pers.h~discontent)) 
m2<-with(a.mids.bss, lm(pers.h.sincerity~discontent)) 
m3<-with(a.mids.bss, lm(pers.h.fairness~discontent)) 
m4<-with(a.mids.bss, lm(pers.h.greedavoidance~discontent))
m5<-with(a.mids.bss, lm(pers.h.modesty~discontent)) 
m6<-with(a.mids.bss, lm(pers.e~discontent)) 
m7<-with(a.mids.bss, lm(pers.e.fearfulness~discontent)) 
m8<-with(a.mids.bss, lm(pers.e.anxiety~discontent)) 
m9<-with(a.mids.bss, lm(pers.e.dependence~discontent)) 
m10<-with(a.mids.bss, lm(pers.e.sentimentality~discontent)) 
m11<-with(a.mids.bss, lm(pers.x~discontent)) 
m12<-with(a.mids.bss, lm(pers.x.socialselfesteem~discontent)) 
m13<-with(a.mids.bss, lm(pers.x.socialboldness~discontent)) 
m14<-with(a.mids.bss, lm(pers.x.sociability~discontent)) 
m15<-with(a.mids.bss, lm(pers.x.liveliness~discontent)) 
m16<-with(a.mids.bss, lm(pers.a~discontent)) 
m17<-with(a.mids.bss, lm(pers.a.forgiveness~discontent)) 
m18<-with(a.mids.bss, lm(pers.a.gentleness~discontent)) 
m19<-with(a.mids.bss, lm(pers.a.flexibility~discontent)) 
m20<-with(a.mids.bss, lm(pers.a.patience~discontent)) 
m21<-with(a.mids.bss, lm(pers.c~discontent)) 
m22<-with(a.mids.bss, lm(pers.c.organization~discontent)) 
m23<-with(a.mids.bss, lm(pers.c.diligence~discontent)) 
m24<-with(a.mids.bss, lm(pers.c.perfectionism~discontent)) 
m25<-with(a.mids.bss, lm(pers.c.prudence~discontent)) 
m26<-with(a.mids.bss, lm(pers.o~discontent)) 
m27<-with(a.mids.bss, lm(pers.o.aestheticappreciation~discontent)) 
m28<-with(a.mids.bss, lm(pers.o.inquisitiveness~discontent)) 
m29<-with(a.mids.bss, lm(pers.o.creativity~discontent)) 
m30<-with(a.mids.bss, lm(pers.o.unconventionality~discontent)) 
m31<-with(a.mids.bss, lm(ideology.freemarket~discontent)) 
m32<-with(a.mids.bss, lm(ideology.democracy~discontent)) 

output <- matrix(data = NA, nrow=32, ncol=5)
output<-data.frame(output)
colnames(output)<-c("measure", "estimate","se")
output$measure<-rep(c("pers.h","pers.h.sincerity","pers.h.fairness","pers.h.greedavoidance","pers.h.modesty","pers.e","pers.e.fearfulness","pers.e.anxiety","pers.e.dependence","pers.e.sentimentality","pers.x","pers.x.socialselfesteem","pers.x.socialboldness","pers.x.sociability","pers.x.liveliness","pers.a","pers.a.forgiveness","pers.a.gentleness","pers.a.flexibility","pers.a.patience","pers.c","pers.c.organization","pers.c.diligence","pers.c.perfectionism","pers.c.prudence","pers.o","pers.o.aestheticappreciation","pers.o.inquisitiveness","pers.o.creativity","pers.o.unconventionality","ideology.freemarket","ideology.democracy"), times=1)
output$label<-rep(c("Honesty-Humility","Honesty-Humility - Sincerity","Honesty-Humility - Fairness","Honesty-Humility - Greed Avoidance","Honesty-Humility - Modesty","Emotionality","Emotionality - Fearfulness","Emotionality - Anxiety","Emotionality - Dependence","Emotionality - Sentimentality","eXtraversion","eXtraversion - Social Self Esteem","eXtraversion - Social Boldness","eXtraversion - Sociability","eXtraversion - Liveliness", "Agreeableness", "Agreeableness - Forgiveness","Agreeableness - Gentleness","Agreeableness - Flexibility","Agreeableness - Patience","Conscientiousness","Conscientiousness - Organization","Conscientiousness - Diligence","Conscientiousness - Perfectionism","Conscientiousness - Prudence","Openness","Openness - Aesthetic Appreciation","Openness - Inquisitiveness","Openness - Creativity","Openness - Unconventionality","Economic Liberalism","Political Liberalism"), times=1)
output$facet<-rep(c("H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","H. Honesty-Humility","E. Emotionality","E. Emotionality","E. Emotionality","E. Emotionality","E. Emotionality","X. Extraversion","X. Extraversion","X. Extraversion","X. Extraversion","X. Extraversion","A. Agreeableness","A. Agreeableness","A. Agreeableness","A. Agreeableness","A. Agreeableness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","C. Conscientiousness","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","O. Openness to Experience","Ideology","Ideology"), times=1)
output$facet2<-output$facet
output$facet2[output$facet=="H. Honesty-Humility"]<-"HEXACO"
output$facet2[output$facet=="E. Emotionality"]<-"HEXACO"
output$facet2[output$facet=="X. Extraversion"]<-"HEXACO"
output$facet2[output$facet=="A. Agreeableness"]<-"HEXACO"
output$facet2[output$facet=="C. Conscientiousness"]<-"HEXACO"
output$facet2[output$facet=="O. Openness to Experience"]<-"HEXACO"
output$facet = factor(output$facet,levels=c("H. Honesty-Humility","E. Emotionality","X. Extraversion", "A. Agreeableness", "C. Conscientiousness", "O. Openness to Experience","Ideology"))
output$facet2 = factor(output$facet2,levels=c("HEXACO","Ideology"))

for (j in 1:32) {
  try(eval(parse(text=paste("output$coeff[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,2]",sep=""))))
  try(eval(parse(text=paste("output$se[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,3]",sep=""))))
}  

output$l95ci<-output$coeff-1.96*output$se
output$u95ci<-output$coeff+1.96*output$se

output$label<-c("honesty-humility","sincerity","fairness","greed avoidance","modesty","emotionality","fearfulness","anxiety","dependence","sentimentality","extraversion","social self-esteem","social boldness","sociability","liveliness","agreeableness","forgiveness","gentleness","flexibility","patience","conscientiousness","organization","diligence","perfectionism","prudence","openness to experience","aesthetic appreciation","inquisitiveness","creativity","unconventionality","pro-market","pro-democracy")
output$exclude<-0
output$exclude[output$measure=="pers.h"]<-1
output$exclude[output$measure=="pers.e"]<-1
output$exclude[output$measure=="pers.x"]<-1
output$exclude[output$measure=="pers.a"]<-1
output$exclude[output$measure=="pers.c"]<-1
output$exclude[output$measure=="pers.o"]<-1
output$exclude[output$measure=="ideology.freemarket"]<-1
output$exclude[output$measure=="ideology.democracy"]<-1
output<-subset(output, output$label!="social dominance orientation")
output.hexaco<-subset(output,output$exclude==0)
output.sum<-subset(output,output$exclude==1 & output$facet!="TIPI")

write.csv(output, "output.bss.csv")
write.csv(output.hexaco, "output.hexaco.bss.csv")
write.csv(output.sum, "output.sum.bss.csv")

pdf('fig-cpt-summary-bss.pdf', width=5.25, height=5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
ggplot(output.sum, aes(x=coeff, y=reorder(label,coeff), color=facet)) + geom_point(size=2, alpha=.7)  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Personality and Other Attributes") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50")  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_segment(aes(y = label, x = l95ci, yend = label, xend = u95ci), alpha=.7, lwd=1, data = output.sum) + scale_colour_manual(values=c("#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#b3b3b3","#b3b3b3","#b3b3b3","#b3b3b3")) + facet_grid(facet2 ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575))
dev.off()

pdf('fig-cpt-subfacets-bss.pdf', width=7, height=5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
ggplot(output.hexaco, aes(x=coeff, y=reorder(label,coeff), colour=facet)) + geom_point(size=2, alpha=.7)  + xlab("Difference in Means (Discontents - Supporters)") + ylab("HEXACO Subfacets") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50") + scale_x_continuous(limits = c(-.65,.65))  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_segment(aes(y = label, x = l95ci, yend = label, xend = u95ci), alpha=.7, lwd=1, data = output.hexaco) + scale_colour_brewer(palette = "Set2", aesthetics = "colour")
dev.off()

#Table: Discriminating Questions between Supporters and Discontents#

for (j in 1:60) {
  try(eval(parse(text=paste("m",j,"<-with(a.mids.bss, lm(H",j,"n~discontent))",sep="")))) 
}  

output <- matrix(data = NA, nrow=60, ncol=5)
output<-data.frame(output)
colnames(output)<-c("measure", "estimate","se")
output$measure<-rep(c("H1n","H2n","H3n","H4n","H5n","H6n","H7n","H8n","H9n","H10n","H11n","H12n","H13n","H14n","H15n","H16n","H17n","H18n","H19n","H20n","H21n","H22n","H23n","H24n","H25n","H26n","H27n","H28n","H29n","H30n","H31n","H32n","H33n","H34n","H35n","H36n","H37n","H38n","H39n","H40n","H41n","H42n","H43n","H44n","H45n","H46n","H47n","H48n","H49n","H50n","H51n","H52n","H53n","H54n","H55n","H56n","H57n","H58n","H59n","H60n"), times=1)

for (j in 1:60) {
  try(eval(parse(text=paste("output$coeff[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,2]",sep=""))))
  try(eval(parse(text=paste("output$se[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,3]",sep=""))))
}  

output$coeff.abs<-abs(output$coeff)
view(output)

write.csv(output, "output.questions.bss.csv")

rm(list=setdiff(ls(), c("a.out.cpt","data.cpt","a.out.bss","data.bss")))

######CHINA URBAN GOVERNANCE SURVEY######

###LOAD DATA###
data.cugs <- read.csv("CUGS Final Data.csv",stringsAsFactors=FALSE)

###CORRECTIONS###

data.cugs$SITECITY[which(data.cugs$SITECITY == "毫州")] <- "亳州"

data.cugs$year <- 2018
data.cugs$date <- as.Date(paste0(data.cugs$year, "-", data.cugs$INTMON, "-", data.cugs$INTDAT))

data.cugs <- as.data.frame(data.cugs) # convert it to the most basic data format
data.cugs <- data.cugs[is.na(data.cugs$date) == FALSE, ]


###GENERATE BASIC VARIABLES###

##Demographics##

#female
data.cugs$female<-NA
data.cugs$female[data.cugs$male=="1"]<-0
data.cugs$female[data.cugs$male=="0"]<-1
summary(data.cugs$female)
sd(data.cugs$female, na.rm=TRUE)

#age 
data.cugs$age
summary(data.cugs$age)
sd(data.cugs$age, na.rm=TRUE)

#minority
data.cugs$minority<-NA
data.cugs$minority[data.cugs$XA7=="汉族"]<-0
data.cugs$minority[data.cugs$XA7=="少数民族"]<-1
summary(data.cugs$minority)
sd(data.cugs$minority, na.rm=TRUE)

#lowed
data.cugs$A4 <- as.numeric(data.cugs$A4)
colnames(data.cugs)[colnames(data.cugs) == "A4"] <- "edu.years"

data.cugs$lowed<-NA
data.cugs$lowed[data.cugs$A4A=="小学以下"]<-1
data.cugs$lowed[data.cugs$A4A=="小学"]<-1
data.cugs$lowed[data.cugs$A4A=="初中"]<-1
data.cugs$lowed[data.cugs$A4A=="高中"]<-1
data.cugs$lowed[data.cugs$A4A=="职高/中专"]<-1
data.cugs$lowed[data.cugs$A4A=="大专"]<-1
data.cugs$lowed[data.cugs$A4A=="大学"]<-0
data.cugs$lowed[data.cugs$A4A=="硕士"]<-0
data.cugs$lowed[data.cugs$A4A=="博士"]<-0
summary(data.cugs$lowed)

#edulevels 
data.cugs$edu.univ<-NA
data.cugs$edu.univ[data.cugs$A4A=="小学以下"]<-0
data.cugs$edu.univ[data.cugs$A4A=="小学"]<-0
data.cugs$edu.univ[data.cugs$A4A=="初中"]<-0
data.cugs$edu.univ[data.cugs$A4A=="高中"]<-0
data.cugs$edu.univ[data.cugs$A4A=="职高/中专"]<-0
data.cugs$edu.univ[data.cugs$A4A=="大专"]<-0
data.cugs$edu.univ[data.cugs$A4A=="大学"]<-1
data.cugs$edu.univ[data.cugs$A4A=="硕士"]<-0
data.cugs$edu.univ[data.cugs$A4A=="博士"]<-0
summary(data.cugs$edu.univ)
sd(data.cugs$edu.univ, na.rm=TRUE)


data.cugs$edu.maphd<-NA
data.cugs$edu.maphd[data.cugs$A4A=="小学以下"]<-0
data.cugs$edu.maphd[data.cugs$A4A=="小学"]<-0
data.cugs$edu.maphd[data.cugs$A4A=="初中"]<-0
data.cugs$edu.maphd[data.cugs$A4A=="高中"]<-0
data.cugs$edu.maphd[data.cugs$A4A=="职高/中专"]<-0
data.cugs$edu.maphd[data.cugs$A4A=="大专"]<-0
data.cugs$edu.maphd[data.cugs$A4A=="大学"]<-0
data.cugs$edu.maphd[data.cugs$A4A=="硕士"]<-1
data.cugs$edu.maphd[data.cugs$A4A=="博士"]<-1

summary(data.cugs$edu.maphd)
sd(data.cugs$edu.maphd, na.rm=TRUE)

#ccp 
data.cugs$K18 <- ifelse(data.cugs$K18 == "是", 1, ifelse(data.cugs$K18 == "不是", 0, NA))
colnames(data.cugs)[colnames(data.cugs) == "K18"] <- "ccp"
summary(data.cugs$ccp)
sd(data.cugs$ccp, na.rm=TRUE)

#sat.central  
unique(data.cugs$B1A)
data.cugs$B1A[which(data.cugs$B1A == "非常不满意")] <- 0
data.cugs$B1A[which(data.cugs$B1A == "非常满意")] <- 10
data.cugs$B1A <- as.numeric(data.cugs$B1A)
colnames(data.cugs)[colnames(data.cugs) == "B1A"] <- "sat.central"
data.cugs$sat.central 
ftable(data.cugs$sat.central)
hist(data.cugs$sat.central)
summary(data.cugs$sat.central)
sd(data.cugs$sat.central, na.rm=TRUE)

#sat.local
data.cugs$B1B[which(data.cugs$B1B == "非常不满意")] <- 0
data.cugs$B1B[which(data.cugs$B1B == "非常满意")] <- 10
data.cugs$B1B <- as.numeric(data.cugs$B1B)
colnames(data.cugs)[colnames(data.cugs) == "B1B"] <- "sat.local"
ftable(data.cugs$sat.local)
hist(data.cugs$sat.local)
summary(data.cugs$sat.local)
sd(data.cugs$sat.local, na.rm=TRUE)

#discontent 
data.cugs$discontent<-NA
data.cugs$discontent[data.cugs$sat.central=="0"]<-1
data.cugs$discontent[data.cugs$sat.central=="1"]<-1
data.cugs$discontent[data.cugs$sat.central=="2"]<-1
data.cugs$discontent[data.cugs$sat.central=="3"]<-1
data.cugs$discontent[data.cugs$sat.central=="4"]<-1
data.cugs$discontent[data.cugs$sat.central=="5"]<-0
data.cugs$discontent[data.cugs$sat.central=="6"]<-0
data.cugs$discontent[data.cugs$sat.central=="7"]<-0
data.cugs$discontent[data.cugs$sat.central=="8"]<-0
data.cugs$discontent[data.cugs$sat.central=="9"]<-0
data.cugs$discontent[data.cugs$sat.central=="10"]<-0

data.cugs.discontent<-subset(data.cugs, data.cugs$discontent==1)
data.cugs.supporter<-subset(data.cugs, data.cugs$discontent==0)
summary(data.cugs$discontent)
sd(data.cugs$discontent, na.rm=TRUE)

data.cugs$discontent.alt<-NA
data.cugs$discontent.alt[data.cugs$sat.central=="0"]<-1
data.cugs$discontent.alt[data.cugs$sat.central=="1"]<-1
data.cugs$discontent.alt[data.cugs$sat.central=="2"]<-1
data.cugs$discontent.alt[data.cugs$sat.central=="3"]<-1
data.cugs$discontent.alt[data.cugs$sat.central=="4"]<-1
data.cugs$discontent.alt[data.cugs$sat.central=="5"]<-1
data.cugs$discontent.alt[data.cugs$sat.central=="6"]<-1
data.cugs$discontent.alt[data.cugs$sat.central=="7"]<-0
data.cugs$discontent.alt[data.cugs$sat.central=="8"]<-0
data.cugs$discontent.alt[data.cugs$sat.central=="9"]<-0
data.cugs$discontent.alt[data.cugs$sat.central=="10"]<-0

data.cugs$tipi1.n[data.cugs$XG16A1=="非常同意"]<-5
data.cugs$tipi1.n[data.cugs$XG16A1=="比较同意"]<-4
data.cugs$tipi1.n[data.cugs$XG16A1=="一般"]<-3
data.cugs$tipi1.n[data.cugs$XG16A1=="不太同意"]<-2
data.cugs$tipi1.n[data.cugs$XG16A1=="非常不同意"]<-1
  
data.cugs$tipi2.n[data.cugs$XG16B1=="非常同意"]<-1
data.cugs$tipi2.n[data.cugs$XG16B1=="比较同意"]<-2
data.cugs$tipi2.n[data.cugs$XG16B1=="一般"]<-3
data.cugs$tipi2.n[data.cugs$XG16B1=="不太同意"]<-4
data.cugs$tipi2.n[data.cugs$XG16B1=="非常不同意"]<-5

data.cugs$tipi3.n[data.cugs$XG16J1=="非常同意"]<-5
data.cugs$tipi3.n[data.cugs$XG16J1=="比较同意"]<-4
data.cugs$tipi3.n[data.cugs$XG16J1=="一般"]<-3
data.cugs$tipi3.n[data.cugs$XG16J1=="不太同意"]<-2
data.cugs$tipi3.n[data.cugs$XG16J1=="非常不同意"]<-1

data.cugs$tipi4.n[data.cugs$XG16C1=="非常同意"]<-1
data.cugs$tipi4.n[data.cugs$XG16C1=="比较同意"]<-2
data.cugs$tipi4.n[data.cugs$XG16C1=="一般"]<-3
data.cugs$tipi4.n[data.cugs$XG16C1=="不太同意"]<-4
data.cugs$tipi4.n[data.cugs$XG16C1=="非常不同意"]<-5

data.cugs$tipi5.n[data.cugs$XG16D1=="非常同意"]<-5
data.cugs$tipi5.n[data.cugs$XG16D1=="比较同意"]<-4
data.cugs$tipi5.n[data.cugs$XG16D1=="一般"]<-3
data.cugs$tipi5.n[data.cugs$XG16D1=="不太同意"]<-2
data.cugs$tipi5.n[data.cugs$XG16D1=="非常不同意"]<-1

data.cugs$tipi6.n[data.cugs$XG16E1=="非常同意"]<-1
data.cugs$tipi6.n[data.cugs$XG16E1=="比较同意"]<-2
data.cugs$tipi6.n[data.cugs$XG16E1=="一般"]<-3
data.cugs$tipi6.n[data.cugs$XG16E1=="不太同意"]<-4
data.cugs$tipi6.n[data.cugs$XG16E1=="非常不同意"]<-5

data.cugs$tipi7.n[data.cugs$XG16F1=="非常同意"]<-5
data.cugs$tipi7.n[data.cugs$XG16F1=="比较同意"]<-4
data.cugs$tipi7.n[data.cugs$XG16F1=="一般"]<-3
data.cugs$tipi7.n[data.cugs$XG16F1=="不太同意"]<-2
data.cugs$tipi7.n[data.cugs$XG16F1=="非常不同意"]<-1

data.cugs$tipi8.n[data.cugs$XG16G1=="非常同意"]<-1
data.cugs$tipi8.n[data.cugs$XG16G1=="比较同意"]<-2
data.cugs$tipi8.n[data.cugs$XG16G1=="一般"]<-3
data.cugs$tipi8.n[data.cugs$XG16G1=="不太同意"]<-4
data.cugs$tipi8.n[data.cugs$XG16G1=="非常不同意"]<-5

data.cugs$tipi9.n[data.cugs$XG16H1=="非常同意"]<-5
data.cugs$tipi9.n[data.cugs$XG16H1=="比较同意"]<-4
data.cugs$tipi9.n[data.cugs$XG16H1=="一般"]<-3
data.cugs$tipi9.n[data.cugs$XG16H1=="不太同意"]<-2
data.cugs$tipi9.n[data.cugs$XG16H1=="非常不同意"]<-1

data.cugs$tipi10.n[data.cugs$XG16I1=="非常同意"]<-1
data.cugs$tipi10.n[data.cugs$XG16I1=="比较同意"]<-2
data.cugs$tipi10.n[data.cugs$XG16I1=="一般"]<-3
data.cugs$tipi10.n[data.cugs$XG16I1=="不太同意"]<-4
data.cugs$tipi10.n[data.cugs$XG16I1=="非常不同意"]<-5

data.cugs$tipi.pers.x <- (data.cugs$tipi1.n+data.cugs$tipi6.n)/2  
data.cugs$tipi.pers.a <- (data.cugs$tipi2.n+data.cugs$tipi7.n)/2
data.cugs$tipi.pers.c <- (data.cugs$tipi3.n+data.cugs$tipi8.n)/2
data.cugs$tipi.pers.e <- (data.cugs$tipi4.n+data.cugs$tipi9.n)/2
data.cugs$tipi.pers.o <- (data.cugs$tipi5.n+data.cugs$tipi10.n)/2

##Political Ideology##

data.cugs$C2an[data.cugs$F9A=="非常同意"]<-4
data.cugs$C2an[data.cugs$F9A=="比较同意"]<-3
data.cugs$C2an[data.cugs$F9A=="不太同意"]<-2
data.cugs$C2an[data.cugs$F9A=="非常不同意"]<-1

data.cugs$C2bn[data.cugs$F9B=="非常同意"]<-1
data.cugs$C2bn[data.cugs$F9B=="比较同意"]<-2
data.cugs$C2bn[data.cugs$F9B=="不太同意"]<-3
data.cugs$C2bn[data.cugs$F9B=="非常不同意"]<-3

data.cugs$C2cn[data.cugs$F9C=="非常同意"]<-1
data.cugs$C2cn[data.cugs$F9C=="比较同意"]<-2
data.cugs$C2cn[data.cugs$F9C=="不太同意"]<-3
data.cugs$C2cn[data.cugs$F9C=="非常不同意"]<-4

data.cugs$C2dn[data.cugs$F9D=="非常同意"]<-1
data.cugs$C2dn[data.cugs$F9D=="比较同意"]<-2
data.cugs$C2dn[data.cugs$F9D=="不太同意"]<-3
data.cugs$C2dn[data.cugs$F9D=="非常不同意"]<-4

data.cugs$C2en[data.cugs$F9E=="非常同意"]<-1
data.cugs$C2en[data.cugs$F9E=="比较同意"]<-2
data.cugs$C2en[data.cugs$F9E=="不太同意"]<-3
data.cugs$C2en[data.cugs$F9E=="非常不同意"]<-4

data.cugs$C2fn[data.cugs$G10A=="非常同意"]<-1 
data.cugs$C2fn[data.cugs$G10A=="比较同意"]<-2
data.cugs$C2fn[data.cugs$G10A=="不太同意"]<-3
data.cugs$C2fn[data.cugs$G10A=="非常不同意"]<-4

data.cugs$C2gn[data.cugs$G10B=="非常同意"]<-1
data.cugs$C2gn[data.cugs$G10B=="比较同意"]<-2
data.cugs$C2gn[data.cugs$G10B=="不太同意"]<-3
data.cugs$C2gn[data.cugs$G10B=="非常不同意"]<-4

data.cugs$C2hn[data.cugs$G10C=="非常同意"]<-4
data.cugs$C2hn[data.cugs$G10C=="比较同意"]<-3
data.cugs$C2hn[data.cugs$G10C=="不太同意"]<-2
data.cugs$C2hn[data.cugs$G10C=="非常不同意"]<-1

data.cugs$C2in[data.cugs$G10D=="非常同意"]<-1
data.cugs$C2in[data.cugs$G10D=="比较同意"]<-2
data.cugs$C2in[data.cugs$G10D=="不太同意"]<-3
data.cugs$C2in[data.cugs$G10D=="非常不同意"]<-4

data.cugs$C2jn[data.cugs$G10E=="非常同意"]<-1
data.cugs$C2jn[data.cugs$G10E=="比较同意"]<-2
data.cugs$C2jn[data.cugs$G10E=="不太同意"]<-3
data.cugs$C2jn[data.cugs$G10E=="非常不同意"]<-4

data.cugs$C2kn[data.cugs$G10F=="非常同意"]<-4
data.cugs$C2kn[data.cugs$G10F=="比较同意"]<-3
data.cugs$C2kn[data.cugs$G10F=="不太同意"]<-2
data.cugs$C2kn[data.cugs$G10F=="非常不同意"]<-1

data.cugs$ideology.freemarket <- (data.cugs$C2an + data.cugs$C2bn + data.cugs$C2fn + data.cugs$C2gn + data.cugs$C2hn +  data.cugs$C2in + data.cugs$C2jn)  / 7   
data.cugs$ideology.democracy <- (data.cugs$C2cn + data.cugs$C2dn + data.cugs$C2en + data.cugs$C2kn)  / 4   

data.cugs$discontent.dem<-NA
data.cugs$discontent.dem[data.cugs$ideology.democracy<2.9999]<-0
data.cugs$discontent.dem[data.cugs$ideology.democracy>2.9999]<-1

summary(data.cugs$ideology.freemarket)
sd(data.cugs$ideology.freemarket, na.rm=TRUE)

summary(data.cugs$ideology.democracy)
sd(data.cugs$ideology.democracy, na.rm=TRUE)

###ANALYSIS###

#Figure: Distribution of Regime Support#

data.bar.cugs<-data.frame(ftable(data.cugs$sat.central))
colnames(data.bar.cugs)<-c("support","frequency")
data.bar.cugs$group<-"Supporter"
data.bar.cugs$group[data.bar.cugs$support=="4"]<-"Discontent"
data.bar.cugs$group[data.bar.cugs$support=="3"]<-"Discontent"
data.bar.cugs$group[data.bar.cugs$support=="2"]<-"Discontent"
data.bar.cugs$group[data.bar.cugs$support=="1"]<-"Discontent"
data.bar.cugs$group[data.bar.cugs$support=="0"]<-"Discontent"

pdf('fig-regsupport-cugs.pdf', width=5.25, height=3.5)
ggplot(data.bar.cugs, aes(x=support, y=frequency, colour=group, fill=group)) + geom_col(alpha=.5,width=.7) +theme_bw() + xlab("Satisfaction with Central Government") + ylab("Count")  +  geom_vline(xintercept = 5.5, size=.5, color="grey50",lty="dashed") + annotate("text", x=3, y = 350, label = "Discontents",color="grey20", size=3.75)  + annotate("text", x=3, y = 200, label = "n=139, 4.1%",color="grey20", size=3.65) + scale_color_manual(values=c("#fc8d62","grey50"),guide=FALSE, aesthetics = c("fill","color"))
dev.off()

write.csv(data.bar.cugs, "data.bar.cugs.csv")

#Figure: Personality and Regime Support#

m1<-lm(ideology.freemarket~discontent, data=data.cugs)
m2<-lm(ideology.democracy~discontent, data=data.cugs)
m3<-lm(tipi.pers.e~discontent, data=data.cugs)
m4<-lm(tipi.pers.x~discontent, data=data.cugs) 
m5<-lm(tipi.pers.a~discontent, data=data.cugs) 
m6<-lm(tipi.pers.c~discontent, data=data.cugs) 
m7<-lm(tipi.pers.o~discontent, data=data.cugs)

output <- matrix(data = NA, nrow=7, ncol=5)
output<-data.frame(output)
colnames(output)<-c("measure", "estimate","se")
output$measure<-rep(c("ideology.freemarket","ideology.democracy","tipi.pers.e","tipi.pers.x","tipi.pers.a","tipi.pers.c","tipi.pers.o"), times=1)
output$label<-rep(c("Economic Liberalism","Political Liberalism", "Emotionality","eXtraversion","Agreeableness","Conscientiousness","Openness to Experience"), times=1)
output$facet<-rep(c("Ideology","Ideology","E. Emotionality","X. Extraversion", "A. Agreeableness", "C. Conscientiousness", "O. Openness to Experience"), times=1)
output$facet = factor(output$facet,levels=c("E. Emotionality","X. Extraversion","A. Agreeableness","C. Conscientiousness","O. Openness to Experience","Ideology"))
output$facet2<-rep(c("Ideology","Ideology","TIPI FFM","TIPI FFM", "TIPI FFM", "TIPI FFM", "TIPI FFM"), times=1)
output$facet2 = factor(output$facet2,levels=c("TIPI FFM","Ideology"))

for (j in 1:7) {
  try(eval(parse(text=paste("t",j,"<-tidy(m",j,")",sep=""))))
  try(eval(parse(text=paste("output$coeff[",j,"]<-as.numeric(t",j,"[2,2])",sep=""))))
  try(eval(parse(text=paste("output$se[",j,"]<-as.numeric(t",j,"[2,3])",sep=""))))
} 

output$l95ci<-as.numeric(output$coeff)-1.96*as.numeric(output$se)
output$u95ci<-as.numeric(output$coeff)+1.96*as.numeric(output$se)

output$label<-c("pro-market","pro-democracy","emotionality","extraversion","agreeableness","conscientiousness","openness to experience")
output$exclude<-0
output$exclude[output$measure=="ideology.freemarket"]<-1
output$exclude[output$measure=="ideology.democracy"]<-1
output$exclude[output$measure=="tipi.pers.e"]<-1
output$exclude[output$measure=="tipi.pers.x"]<-1
output$exclude[output$measure=="tipi.pers.a"]<-1
output$exclude[output$measure=="tipi.pers.c"]<-1
output$exclude[output$measure=="tipi.pers.o"]<-1
output<-subset(output, output$label!="social dominance orientation")
output.sum<-subset(output,output$exclude==1)
write.csv(output, "output.cugs.csv")
write.csv(output.sum, "output.sum.cugs.csv")

####COMBINED FIGURES AND TABLES####

rm(list=setdiff(ls(), c("a.out.cpt","data.cpt","a.out.bss","data.bss", "data.cugs")))

g_legend<-function(a.gplot){
  tmp <- ggplot_gtable(ggplot_build(a.gplot))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  return(legend)}
library(gridExtra)

require(grid)
vp.layout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y)
arrange_ggplot2 <- function(..., nrow=NULL, ncol=NULL, as.table=FALSE) {
  dots <- list(...)
  n <- length(dots)
  if(is.null(nrow) & is.null(ncol)) { nrow = floor(n/2) ; ncol = ceiling(n/nrow)}
  if(is.null(nrow)) { nrow = ceiling(n/ncol)}
  if(is.null(ncol)) { ncol = ceiling(n/nrow)}
  
  grid.newpage()
  pushViewport(viewport(layout=grid.layout(nrow,ncol) ) )
  ii.p <- 1
  for(ii.row in seq(1, nrow)){
    ii.table.row <- ii.row  
    if(as.table) {ii.table.row <- nrow - ii.table.row + 1}
    for(ii.col in seq(1, ncol)){
      ii.table <- ii.p
      if(ii.p > n) break
      print(dots[[ii.table]], vp=vp.layout(ii.table.row, ii.col))
      ii.p <- ii.p + 1
    }
  }
}

#Figure: Distribution of Regime Support

data.bar.cpt<-read.csv("data.bar.cpt.csv") 
data.bar.bss<-read.csv("data.bar.bss.csv")  
data.bar.cugs<-read.csv("data.bar.cugs.csv")  

pdf('fig-regsupport-combined.pdf', width=8.5, height=3.25)
p1<-ggplot(data.bar.cpt, aes(x=support, y=frequency, colour=group, fill=group)) + ggtitle("China Personality Test (2017)") + geom_col(alpha=.5,width=.7) +theme_bw() + xlab("Satisfaction with Central Govt") + ylab("Count")  +  geom_vline(xintercept = 4.5, size=.5, color="grey50",lty="dashed") + annotate("text", x=2, y = 145, label = "Discontents",color="grey20", size=2.9)  + annotate("text", x=2, y = 95, label = "n=106, 5.2%",color="grey20", size=2.8) + scale_color_manual(values=c("#fc8d62","grey50"),guide=FALSE, aesthetics = c("fill","color")) + ylim(c(0,500)) + theme(plot.title = element_text(size = 9), axis.title = element_text(size = 9)) 
p2<-ggplot(data.bar.cugs, aes(x=support, y=frequency, colour=group, fill=group)) + ggtitle("China Urban Governance Survey (2018)") + geom_col(alpha=.5,width=.7) +theme_bw() + xlab("Satisfaction with Central Govt") + ylab("Count")  +  geom_vline(xintercept = 4.5, size=.5, color="grey50",lty="dashed") + annotate("text", x=2, y = 370, label = "Discontents",color="grey20", size=2.9)  + annotate("text", x=2, y = 240, label = "n=139, 4.1%",color="grey20", size=2.8) + scale_color_manual(values=c("#fc8d62","grey50"),guide=FALSE, aesthetics = c("fill","color")) + ylim(c(0,1400)) + theme(plot.title = element_text(size = 9), axis.title = element_text(size = 9))
p3<-ggplot(data.bar.bss, aes(x=support, y=frequency, colour=group, fill=group)) + ggtitle("Beijing Student Survey (2018)") + geom_col(alpha=.5,width=.7) +theme_bw() + xlab("Satisfaction with Central Govt") + ylab("Count")  +  geom_vline(xintercept = 4.5, size=.5, color="grey50",lty="dashed") + annotate("text", x=2, y = 150, label = "Discontents",color="grey20", size=2.9)  + annotate("text", x=2, y = 100, label = "n=89, 4.7%",color="grey20", size=2.8) + scale_color_manual(values=c("#fc8d62","grey50"),guide=FALSE, aesthetics = c("fill","color")) + ylim(c(0,575)) + theme(plot.title = element_text(size = 9), axis.title = element_text(size = 9))
arrange_ggplot2(p1,p2,p3, nrow=1, ncol=3)
dev.off()

#Figure: Personality and Regime Support 

output.sum.cpt<-read.csv("output.sum.cpt.csv")
output.sum.bss<-read.csv("output.sum.bss.csv")
output.sum.cugs<-read.csv("output.sum.cugs.csv")

output.sum.cpt$study<-"CPT"
output.sum.bss$study<-"BSS"
output.sum.cugs$study<-"CUGS"

output.sum<-rbind(output.sum.cpt,output.sum.bss, output.sum.cugs)
write.csv(output.sum, "output.sum.csv")
output.sum$facet = factor(output.sum$facet,levels=c("H. Honesty-Humility","E. Emotionality","X. Extraversion", "A. Agreeableness", "C. Conscientiousness", "O. Openness to Experience", "Dark Triad", "SDO","IQ","Ideology","TIPI"))
output.sum$facet2 = factor(output.sum$facet2,levels=c("HEXACO", "TIPI FFM", "Dark Triad", "SDO","Ideology", "IQ"))

output.sum$pvalue.onesided<-output.sum$pvalue/2
output.sum$pvalue.onesided[output.sum$coeff>0]<-1-(output.sum$pvalue/2)
sumlog(output.sum$pvalue.onesided[output.sum$facet=="H. Honesty-Humility"])
sumlog(output.sum$pvalue.onesided[output.sum$facet=="X. Extraversion"])
sumlog(output.sum$pvalue.onesided[output.sum$facet=="C. Conscientiousness"])
sumlog(output.sum$pvalue.onesided[output.sum$facet=="O. Openness to Experience"])
sumlog(output.sum$pvalue.onesided[output.sum$facet=="A. Agreeableness"])

output.tipi<-subset(output.sum, output.sum$facet2=="TIPI FFM")
output.sum<-subset(output.sum, output.sum$facet2!="TIPI FFM")
output.sum<-subset(output.sum, output.sum$facet2!="Dark Triad")
output.tipi$label2<-c("emotional stability","extraversion","agreeableness","conscientiousness","openness to experience","emotional stability","extraversion","agreeableness","conscientiousness","openness to experience")
  
pdf('fig-summary-combined.pdf', width=6.55, height=4.5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
ggplot(output.sum, aes(x=coeff, y=reorder(label,coeff), color=facet, lty=study, shape=study)) + geom_point(size=2.5, alpha=.7, position=ggstance::position_dodgev(height=0.75))  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Personality and Other Attributes") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50")  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_errorbarh(aes(y = label, xmin = l95ci, xmax = u95ci), alpha=.7, lwd=1, data = output.sum, position=ggstance::position_dodgev(height=0.75), height=0) +  scale_colour_manual(values=c("#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","grey40","grey40","grey40","grey40")) + facet_grid(facet2 ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="bottom") + coord_cartesian(xlim = c(-.575,.575)) + scale_linetype_manual(values=c("dotted", "solid","longdash"))  + guides(colour = "none")
dev.off()  

pdf('fig-summary-combined-tipi.pdf', width=6.55, height=3.5)     
ggplot(output.tipi, aes(x=coeff, y=reorder(label2,coeff), color=facet, lty=study, shape=study)) + geom_point(size=2.5, alpha=.7, position=ggstance::position_dodgev(height=0.75))  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Personality and Other Attributes") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50")  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) +  geom_errorbarh(aes(y = label2, xmin = l95ci, xmax = u95ci), alpha=.7, lwd=1, data = output.tipi, position=ggstance::position_dodgev(height=0.75), height=0) +  scale_colour_manual(values=c("#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f")) + facet_grid(facet2 ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="bottom") + coord_cartesian(xlim = c(-.575,.575)) + scale_linetype_manual(values=c("dotted", "solid","longdash"))  + guides(colour = "none")
dev.off()

#Figure: Personality Subfacets and Regime Support

output.hexaco.cpt<-read.csv("output.hexaco.cpt.csv")
output.hexaco.bss<-read.csv("output.hexaco.bss.csv")

output.hexaco.cpt$study<-"China Personality Test"
output.hexaco.bss$study<-"Beijing Student Survey"

output.hexaco<-rbind(output.hexaco.cpt,output.hexaco.bss)
output.hexaco.cpt$facet = factor(output.hexaco.cpt$facet,levels=c("H. Honesty-Humility","E. Emotionality","X. Extraversion", "A. Agreeableness", "C. Conscientiousness", "O. Openness to Experience"))
output.hexaco.bss$facet = factor(output.hexaco.bss$facet,levels=c("H. Honesty-Humility","E. Emotionality","X. Extraversion", "A. Agreeableness", "C. Conscientiousness", "O. Openness to Experience"))

p1<-ggplot(output.hexaco.cpt, aes(x=coeff, y=reorder(label,coeff), colour=facet)) + geom_point(size=2.5, alpha=.7)  + xlab("Difference in Means (Discontents - Supporters)") + ylab("HEXACO Facets") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50") + coord_cartesian(xlim = c(-.75, .75))  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) + geom_errorbarh(aes(y = label, xmin = l95ci, xmax = u95ci), alpha=.7, lwd=1, data = output.hexaco.cpt, height=0) + scale_colour_brewer(palette = "Set2", aesthetics = "colour")  + theme(legend.position="bottom") + ggtitle("China Personality Test (2017)") + theme(plot.title = element_text(size = 9))
p2<-ggplot(output.hexaco.bss, aes(x=coeff, y=reorder(label,coeff), colour=facet)) + geom_point(size=2.5, alpha=.7)  + xlab("Difference in Means (Discontents - Supporters)") + ylab("HEXACO Facets") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = FALSE)+ theme_bw() + geom_vline(xintercept = 0.0, size=.5, color="grey50") +  coord_cartesian(xlim = c(-.75, .75))  + theme(legend.title=element_blank()) + theme(axis.title.x = element_text(size=9)) + theme(axis.title.y = element_text(size=9)) + geom_errorbarh(aes(y = label, xmin = l95ci, xmax = u95ci), alpha=.7, lwd=1, data = output.hexaco.bss, height=0) + scale_colour_brewer(palette = "Set2", aesthetics = "colour") + ggtitle("Beijing Student Survey (2018)") + theme(plot.title = element_text(size = 9))
mylegend<-g_legend(p1)

pdf('fig-subfacets-combined.pdf', width=8.5, height=5.5)                                                                                                                                                                                                                                                                                                                                                                                                                                              
plot <- grid.arrange(arrangeGrob(p1 + theme(legend.position="none"),p2 + theme(legend.position="none"),nrow=1,ncol=2),mylegend, nrow=2,heights=c(10, 1))
dev.off()

#Figure: Determinants of Discontent 

a.cpt.mids <- miceadds::datlist2mids(a.out.cpt$imputations)
a.bss.mids <- miceadds::datlist2mids(a.out.bss$imputations)

m1<-with(a.cpt.mids, lm(sat.central~pers.h+pers.e+pers.x+pers.a+pers.c+pers.o))
summary(pool(m1))
m2<-with(a.cpt.mids, lm(sat.central~pers.h+pers.e+pers.x+pers.a+pers.c+pers.o+female+minority+lowed+ccp+rtotal.correct))
summary(pool(m2))

m3<-with(a.bss.mids, lm(sat.central~pers.h+pers.e+pers.x+pers.a+pers.c+pers.o))
summary(pool(m3))
m4<-with(a.bss.mids, lm(sat.central~pers.h+pers.e+pers.x+pers.a+pers.c+pers.o+female+minority+ccp))
summary(pool(m4))

texreg(list(pool(m1), pool(m2), pool(m3), pool(m4)), booktabs = TRUE, dcolumn = TRUE)


#Figure: Robustness Checks 

a.cpt.mids <- miceadds::datlist2mids(a.out.cpt$imputations)
a.bss.mids <- miceadds::datlist2mids(a.out.bss$imputations)

m1<-with(a.cpt.mids, lm(pers.e~discontent))
m2<-with(a.cpt.mids, lm(pers.e~discontent.alt))
m3<-lm(pers.e~discontent, data=data.cpt)
m4<-lm(pers.e~discontent.alt, data=data.cpt) 
m5<-with(a.bss.mids, lm(pers.e~discontent))
m6<-with(a.bss.mids, lm(pers.e~discontent.alt))

m7<-with(a.cpt.mids, lm(pers.x~discontent))
m8<-with(a.cpt.mids, lm(pers.x~discontent.alt))
m9<-lm(pers.x~discontent, data=data.cpt)
m10<-lm(pers.x~discontent.alt, data=data.cpt) 
m11<-with(a.bss.mids, lm(pers.x~discontent))
m12<-with(a.bss.mids, lm(pers.x~discontent.alt))

m13<-with(a.cpt.mids, lm(pers.a~discontent))
m14<-with(a.cpt.mids, lm(pers.a~discontent.alt))
m15<-lm(pers.a~discontent, data=data.cpt)
m16<-lm(pers.a~discontent.alt, data=data.cpt) 
m17<-with(a.bss.mids, lm(pers.a~discontent))
m18<-with(a.bss.mids, lm(pers.a~discontent.alt))

m19<-with(a.cpt.mids, lm(pers.c~discontent))
m20<-with(a.cpt.mids, lm(pers.c~discontent.alt))
m21<-lm(pers.c~discontent, data=data.cpt)
m22<-lm(pers.c~discontent.alt, data=data.cpt) 
m23<-with(a.bss.mids, lm(pers.c~discontent))
m24<-with(a.bss.mids, lm(pers.c~discontent.alt))

m25<-with(a.cpt.mids, lm(pers.o~discontent))
m26<-with(a.cpt.mids, lm(pers.o~discontent.alt))
m27<-lm(pers.o~discontent, data=data.cpt)
m28<-lm(pers.o~discontent.alt, data=data.cpt) 
m29<-with(a.bss.mids, lm(pers.o~discontent))
m30<-with(a.bss.mids, lm(pers.o~discontent.alt))

m31<-with(a.cpt.mids, lm(pers.h~discontent))
m32<-with(a.cpt.mids, lm(pers.h~discontent.alt))
m33<-lm(pers.h~discontent, data=data.cpt)
m34<-lm(pers.h~discontent.alt, data=data.cpt) 
m35<-with(a.bss.mids, lm(pers.h~discontent))
m36<-with(a.bss.mids, lm(pers.h~discontent.alt))

output <- matrix(data = NA, nrow=36, ncol=3)
output<-data.frame(output)
colnames(output)<-c("coeff","se","p")
output$data<-rep(c("CPT","CPT","CPT","CPT","BSS","BSS"), times=1)
output$personality<-rep(c("HEXACO","HEXACO","HEXACO","HEXACO","HEXACO","HEXACO"), times=1)
output$discontent<-rep(c("sat.central<5","sat.central<7","sat.central<5","sat.central<7","sat.central<5","sat.central<7"), times=1)
output$imputation<-rep(c("imputation","imputation","none","none","imputation","imputation"), times=1)
output$facet<-c(rep(c("E. Emotionality"),times=6), rep(c("X. Extraversion"),times=6),rep(c("A. Agreeableness"),times=6),rep(c("C. Conscientiousness"),times=6),rep(c("O. Openness to Experience"),times=6),rep(c("H. Honesty-Humility"),times=6))

for (j in 1:36) {
  try(eval(parse(text=paste("output$coeff[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,2]",sep=""))))
  try(eval(parse(text=paste("output$se[",j,"]<-summary(pool(m",j,"), type = c('tests', 'all'), conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE)[2,3]",sep=""))))
  try(eval(parse(text=paste("t",j,"<-tidy(m",j,")",sep=""))))
  try(eval(parse(text=paste("output[",j,",1]<-as.numeric(t",j,"[2,2])",sep=""))))
  try(eval(parse(text=paste("output[",j,",2]<-as.numeric(t",j,"[2,3])",sep=""))))
}  

output$l95ci<-output$coeff-1.96*output$se
output$u95ci<-output$coeff+1.96*output$se

output$l95ci<-output$coeff-1.96*output$se
output$u95ci<-output$coeff+1.96*output$se
output$label<-rep(c("HEXACO-sat.central<5-imputation","HEXACO-sat.central<7-imputation","HEXACO-sat.central<5-deletion","HEXACO-sat.central<7-deletion","HEXACO-sat.central<5-imputation","HEXACO-sat.central<7-imputation"), times=1)
output.h<-subset(output,output$facet=='H. Honesty-Humility')
output.e<-subset(output,output$facet=='E. Emotionality')
output.x<-subset(output,output$facet=='X. Extraversion')
output.a<-subset(output,output$facet=='A. Agreeableness')
output.c<-subset(output,output$facet=='C. Conscientiousness')
output.o<-subset(output,output$facet=='O. Openness to Experience')

pdf('fig-robustness-h.pdf', width=6.25, height=5)
ggplot(output.h, aes(y=reorder(label,coeff), x=coeff)) + xlim(c(-1,1)) + geom_point(size=2, alpha=.7, color="#66c2a5")  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Specification") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + theme(legend.title=element_blank()) + geom_segment(aes(y = reorder(label,coeff), x = l95ci, xend = u95ci, yend = reorder(label,coeff)), color="#66c2a5", alpha=.4, lwd=.8) + geom_vline(xintercept = 0.0,  lty="dashed", alpha=.6) + facet_grid(data ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575)) 
dev.off()

pdf('fig-robustness-e.pdf', width=6.25, height=5)
ggplot(output.e, aes(y=reorder(label,coeff), x=coeff)) + xlim(c(-1,1)) + geom_point(size=2, alpha=.7, color="#fc8d62")  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Specification") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + theme(legend.title=element_blank()) + geom_segment(aes(y = reorder(label,coeff), x = l95ci, xend = u95ci, yend = reorder(label,coeff)), color="#fc8d62", alpha=.4, lwd=.8) + geom_vline(xintercept = 0.0,  lty="dashed", alpha=.6) + facet_grid(data ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575)) 
dev.off()

pdf('fig-robustness-x.pdf', width=6.25, height=5)
ggplot(output.x, aes(y=reorder(label,coeff), x=coeff)) + xlim(c(-1,1)) + geom_point(size=2, alpha=.7, color="#8da0cb")  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Specification") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + theme(legend.title=element_blank()) + geom_segment(aes(y = reorder(label,coeff), x = l95ci, xend = u95ci, yend = reorder(label,coeff)), color="#8da0cb", alpha=.4, lwd=.8) + geom_vline(xintercept = 0.0,  lty="dashed", alpha=.6) + facet_grid(data ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575)) 
dev.off()

pdf('fig-robustness-a.pdf', width=6.25, height=5)
ggplot(output.a, aes(y=reorder(label,coeff), x=coeff)) + xlim(c(-1,1)) + geom_point(size=2, alpha=.7, color="#e78ac3")  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Specification") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + theme(legend.title=element_blank()) + geom_segment(aes(y = reorder(label,coeff), x = l95ci, xend = u95ci, yend = reorder(label,coeff)), color="#e78ac3", alpha=.4, lwd=.8) + geom_vline(xintercept = 0.0,  lty="dashed", alpha=.6) + facet_grid(data ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575)) 
dev.off()

pdf('fig-robustness-c.pdf', width=6.25, height=5)
ggplot(output.c, aes(y=reorder(label,coeff), x=coeff)) + xlim(c(-1,1)) + geom_point(size=2, alpha=.7, color="#a6d854")  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Specification") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + theme(legend.title=element_blank()) + geom_segment(aes(y = reorder(label,coeff), x = l95ci, xend = u95ci, yend = reorder(label,coeff)), color="#a6d854", alpha=.4, lwd=.8) + geom_vline(xintercept = 0.0,  lty="dashed", alpha=.6) + facet_grid(data ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575))
dev.off()

pdf('fig-robustness-o.pdf', width=7.25, height=5)
ggplot(output.o, aes(y=reorder(label,coeff), x=coeff)) + xlim(c(-1,1)) + geom_point(size=2, alpha=.7, color="#ffd92f")  + xlab("Difference in Means (Discontents - Supporters)") + ylab("Specification") + theme(plot.title = element_text(lineheight=.8, face="bold")) + scale_shape(solid = TRUE)+ theme_bw() + theme(legend.title=element_blank()) + geom_segment(aes(y = reorder(label,coeff), x = l95ci, xend = u95ci, yend = reorder(label,coeff)), color="#ffd92f", alpha=.4, lwd=.8) + geom_vline(xintercept = 0.0,  lty="dashed", alpha=.6) + facet_grid(data ~., scales = "free",space = "free") + theme(legend.key = element_blank(), strip.background = element_rect(colour="white", fill="white") ) + theme(legend.position="none") + coord_cartesian(xlim = c(-.575,.575)) 
dev.off()




